chantastic.fm

106: Nikolas Burk on Prisma 2

Episode 106 · August 20, 2020 · 00:58:11

Hosted by chantastic · With Nikolas Burk

Sponsored by Infinite Red

Download MP3 · Jump to transcript

Featuring

Links

Sponsors

Infinite Red

In over your head with a React or React Native app? Infinite Red can help. They're React Native core contributors who've been designing, building and shipping apps for over 10 years. reactpodcast.infinite.red

Transcript

[00:00:00] Michael Chan: This is React Podcast. I'm Chantastic. Today, Nikolas Burk tells us about Prisma 2, modern database access for TypeScript and Node. We talk about the history of database ORMs, object-relational mappers, the product journey of GraphiQL to Prisma 2, and how Prisma is powering new full-stack frameworks like Redwood and Blitz.js. Before we dive in, thanks to Infinite Red for supporting this episode. Having access to developers that know the direction React and React Native are headed can be a huge advantage for your development team, giving you more time spent satisfying customers and less time spent migrating from one state management solution to another. If you don't have developers who know React and React Native like the back of their hand, hire Infinite Red. Infinite Red has been designing, building, and shipping apps for 10 years, and they want to bring their expertise and industry connections to your apps. Infinite Red has this sweet deal right now where you get $750 for referring a new project. Get expert help from Infinite Red by visiting reactpodcast.infinite.red. Nicholas, welcome to React Podcast.

[00:01:25] Nikolas Burk: Hello, Michael. Thanks for having me on the show. Really excited to be here.

[00:01:29] Michael Chan: I'm excited to have you on. I'm excited for our topic today. Um, I know that You know, recently I've been talking uh with a lot of people on this show and other shows about how frustrating it can be for React developers to learn React and then kind of go out into the world and feel like they only have half of what they need to build a full-blown application. And sometimes that's fine, right? Because they, uh you know, they join a team and there's a backend team and they never have to think about that again. Um but other times it's like, you know, they have a vision for an app. And now they're like- they see this huge landscape of uh of products and have no idea uh what to pick. So, I'm really excited to talk with you. Um, you're gonna help us navigate this landscape a little bit today and kind of talk about what's out there and um and tell us about Prisma and what you're doing with them. Um, but first, why don't you just tell me a little bit about um kind of yourself and like what you've been working on for the last uh the last 3 years.

[00:02:28] Nikolas Burk: Cool, yeah, sure. So uh my name is Nikolas Burk. Um I lead the developer success team at Prisma. So our responsibility at Prisma is really to help developers reach their goals with the Prisma tools. And we do that through direct support uh on Slack, on GitHub, on Stack Overflow, like um wherever people ask questions about Prisma, we try to be there and and help them out. And we are also taking care of documentation and example projects. Like occasionally I write blog posts and like other kinds of tutorials on like various kinds of platforms. So in general, I think I'm just really passionate about teaching other developers and and helping them out, trying to help them reach their goals wherever possible. And especially of course, with the Prisma tools.

[00:03:23] Michael Chan: Love that. Yeah, there's- you know, it's it's interesting to me how important it's become for anyone who has a product and is marketing a product to do that work. To, you know, focus on developer success, make sure that everyone has access to, you know, like, just use our tool in 5 minutes, right? Like it's really critical that you have all those resources. Um, so, I love that you're working on that. Now, I want to talk about the the problem right now. Um, I think that we've had, you know, maybe, you know, over the last few years before React really became popular, we had a lot of full-stack frameworks. So you have like your Rails, your Laravel, your, you know, PHP, Cake, uh, you know, like I feel like Java and, you know, all the every language had kind of like a full-stack framework. And there were tools for integrating directly with the database, which was pretty easy because you're, you know, on a server, you're already connected maybe to the the same even physical hardware depending on the size of your app. Um, but a lot of that has changed as we have moved into like client-driven apps. And- Yes. I feel like like uh let's see, like like mobile has been really responsible for driving that. Because, you know, now you can split up your teams. So, you got a backend Exactly.

[00:04:42] Nikolas Burk: And you need an API, right? You didn't need kind of an API before, and now you need an API that has to serve different kinds of client applications. And these might be mobile devices, this might be a browser-based or a desktop application. So you need an API as kind of this intermediate layer in between your client and your database.

[00:05:01] Michael Chan: Yeah, yeah, yeah. And it's it it it's funny how it just kind of like snuck up on us, I guess, right? Because it's like it was like all of a sudden, and Honestly, like, you know, Facebook talks about this too when they talk about like the invention of GraphQL. You know, it was like, for them it was this weird thing where like, oh, like we're so used to just asking the database for stuff. Like now we have to create this API so our mobile apps can can use it. And you know, 7 years later, now we're here. Um, so I want to ask you like what what has that looked like kind of over the last 7 years? Like what have what have those tools kind of been historically that people have reached for as they build more client-heavy apps?

[00:05:41] Nikolas Burk: Yeah, sure. I think I wanna take this from the angle that like you you said initially, where you said that, okay, you're a React developer, you know how to build like a frontend of an application, but you're really only halfway there, right? If you if you have an idea for an application that you wanna build yourself, I mean, you need some way of persisting data, very likely, uh depending on the application that you build. But if you build an e-commerce application, then you kind of need to store your users, your orders, your invoices. If you build a social media application, you again have to store users, images, whatever. And it's very likely that you need a database. And like that can sometimes be very um intimidating for React developers. Yeah. Because they don't really have kind of the the right experience for how to do that. What they're used to is kind of they write their React components, they are handed some API, maybe at their work there is a backend team that is building the API for them and they just access the different API routes or ideally if it's a GraphQL API, they can uh talk to that API, but um they're really not concerned with anything that happens on the server side. Mm-hm. And like really understanding like what your what your options are, um if you're a React developer and you want to build that kind of full-stack uh application is super important. And like that's what I um like think we'll talk a little bit uh uh uh like about today. And um here I can already offer kind of the the first choice that you have to make when you're a React developer and you need the backend, and that's typically the the choice between picking a backend as a service, a so-called backend as a service, I'll explain in a bit what that is, or alternatively, you'll go and code your own backend. Okay. And there you can pick any kind of pro- uh programming language that you're that you're already familiar with. Um you can write it in Node or in TypeScript on the backend, but you might as well choose a programming language like Java or Python, um like whatever you you prefer works on the backend because the communication between your frontend and on the backend will happen through HTTP. And all of these server-side languages happen to have like HTTP web frameworks that you can just plug into your server-side application to serve these HTTP requests.

[00:07:57] Michael Chan: And as of as of yet, there's not like a there's not like a database or a popular database system that allows you to just reach into it through HTTP.

[00:08:06] Nikolas Burk: Exactly, exactly. I mean, like, uh so speaking of backends as a service, I think Maybe Firebase comes fairly close to that model because there you get a fairly direct uh connection to your database, I think. Uh I'm also not that experienced with Firebase, but that's kind of my high-level understanding of it. Um but it's— um yeah, it's not really um like a a popular approach that you would talk to a database right from the frontend. Like having this intermediate API layer- Right. —is just like way more common and also way more scalable. Um since you might add more clients to your application as we discussed in the beginning.

[00:08:47] Michael Chan: Sure.

[00:08:48] Nikolas Burk: So yeah, you can, um, like on a high level, you can think of these uh two choices, backend as a service versus coding your your own backend. And uh a backend as a service, for for those people who don't know, is basically um a way how you can get an API and a database for your application kind of out of the box. Um typically, the the way how these work is that you have like a browser-based application uh where you You would define your data model. So the the the data model then typically gets mapped to the database that is created for you. And um at the same time, they also expose an API for you um that you can access from the front end. And you typically also have kind of uh additional functionality there, like authentication, like very common features um that you need when you build an application uh will be included in that as well. And A few examples for uh backends as a service, I think, are, for example, Firebase or AWS Amplify. Um there used to be Parse back in the day, um GraphiQL, which we'll talk uh a little bit about later, which is kind of relevant in in the history of Prisma as a company. So these are the kinds of options that you have when you are uh picking a backend as a service. And The the problem with these backends as a service often is that they are great until a certain point, until your requirements become so custom to your application that they are not anymore covered uh by the offering of the backend as a service that you're choosing. And at that point, you really wanna go and and build your own backend. And um today, I think we'll talk a little bit about the the different decisions that you'll have to make when you are building your own backend and like probably focusing mostly on the Node and and uh TypeScript ecosystem, since that's probably what what most of the listeners will be familiar with.

[00:10:46] Michael Chan: Yeah, I you know I I I wanna go into that right now, actually, because I think that this is an interesting thing. I know that when I- so I come from uh more of a Rails background, um or you know even even PHP. I used, uh what is it, CodeIgniter back in the day. And so I I am most comfortable, probably even still, uh with that kind kind of, you know, it's just one application and I'm just getting the data that I need and rendering it right out in HTML.

[00:11:12] Nikolas Burk: That big old monolith.

[00:11:14] Michael Chan: Yeah, the big old monolith, right? It's very easy to to to to reason about. Um, and I know that when I was was just kind of just kind of starting into this, um, Firebase was one of the first ones on on the scene. It was a it was a really cool product and and made it really easy to connect to data. Um, but it did kind of have this I was I was nervous because it kind of owned my user data in a way that I was like uncomfortable with. Um and that kind of prevented me from really ever wanting to go like you know whole whole hog on it. Because it was like what if I need to move, if I want to move, if this whole thing doesn't pan out and I end up using Rails for the rest of my life. Um like what does what does this look like? And I'm glad that you brought that up. Um because I know that that's a concern for a lot of people. Um so can we talk a little bit about kind of like what that vendor lock-in looks like and like why it's something that's important to consider.

[00:12:08] Nikolas Burk: So I think uh like one important aspect here is uh like uh the the thing that you already mentioned that you don't really have uh or you you don't really own the data that is being stored, right? It's being stored on a third-party system where you don't have direct access to. So like already on that level, you you kind of have to trust the backend as a service provider enough to store your user data, which is like a very delicate topic.

[00:12:37] Michael Chan: Yeah, that's your business.

[00:12:39] Nikolas Burk: Exactly, exactly. And as far as I can tell, like um most kind of serious businesses want to have their own direct access to the data without having to go through the actual path that is offered by these backend as a service providers. So I think uh like that aspect about uh kind of owning and having full access to the data is already very important. But then And a lot of it also comes down to um like further technology choices like that you wanna make. Um with these kinds of backends as a service, you probably, um most of the time, you can't really do anything of uh like testing or CI/CD on the backend or anything like this. Any um additional requirements that that you have for your application um that are typically not um covered by these providers, um you you just can't do. And if you Um, if you end up finding out that you need this only a year after you've chosen it, then it's the the time where the lock-in really hits you hard because then it'll be a pain to to migrate off of it and actually like making sure that you get your own backend. So I think um like these are typically nice for kind of hobby projects and uh like side projects, but once you start building kind of really mission-critical applications that are the core of a business, then I think you wanna have more control over over the data and uh the the entire stack on the backend, right? It's not only the data, but it's really all the technology choices that are being made on the backend. You have no influence on when you're using a backend as a service.

[00:14:14] Michael Chan: Yeah, yeah, absolutely. Yeah, and so I think I think we've seen a lot of this um actually where like even even with Firebase as an example, right? They're changing their structure a little bit to be, I don't know, it's it's another product now, right? And I think Firebase maybe works on top of it.

[00:14:31] Nikolas Burk: It's a huge platform, I think. I'm also not sure what exactly they're offering by now. But every time I visit their website every 6 months, it looks different and it just grows and grows and grows. So I also don't know what is all included there.

[00:14:44] Michael Chan: Yeah, and it's it it it really does feel like, you know, the the the answer to that is, well, I guess you can't have an easy thing anymore, right? And I I think that that is- I think that's where a lot of people get stuck, right? Like going back to that developer story, it's like, oh, okay, well, like, you know, Firebase, you know, it it seemed like it was gonna answer all my things, but now it's now it's like kind of like pulled apart and it's just as complex as if I, you know, were to like build my build my own thing now. And like maybe you get a little bit of like auth help or whatever, you know. Um, go uh was it um, you know, AWS also has like a bunch of services that you can stitch together to like make this kind of stuff, but it requires a lot of knowledge upfront, which is time that you, you know, aren't spending actually building your application. Totally. Now, I know that that that Prisma has actually gone through like kind of like a similar um similar story. And I'd love to kind of COVID that maybe a little bit later. But um what what do you identify as like the solution? Like where's that sweet spot where it's like you're not stitching together everything, um but then also you're not completely beholden to the technical decisions of like that kind of out-of-the-box easy solution?

[00:15:54] Nikolas Burk: Right. Um, it's actually a really good question and it points to something that I was going to say anyways. I think we will have the uh like conversation about our history as a company and about uh kind of what happened to Graphcool and why we're not uh why we're not continuing it. Like we'll have that a little bit later, but to to tease that already a little bit, maybe. Um, like what we found the the the biggest problem with Graphcool was, was that actually people loved it for its ease of use. Like Yeah. People really, really liked that they could just define their models and out of the box, they got a database with a GraphQL API. That was just really great. But the big problem that we saw was that uh people were just using it for building prototypes and for learning GraphQL. So like they kind of went in and uh started uh building something. And as soon as they kind of validated their idea, they said, okay, thanks. Well, I'm going to implement this myself now because I do need all the control on the backend myself. So um the the sweet spot is, I think, or like what we realized at that point was that the best abstraction ultimately that you can give to developers is code. You have to give them the flexibility to be able to do things in their own ways rather than locking them in into a certain way of API design that might not fit all requirements or whatever um Like whatever else you you have as restrictions in these backends as a services. Um and the the sweet spot I think will be uh like finding a good framework that you feel familiar with, that allows you to be productive and um has kind of the the right architecture that fits your needs. So I think um we are now with Prisma compared to GraphQL, we are operating on a much more level. Much lower level. We're just giving people database tools to to build their server-side applications them uh themselves. And- Hm. So with that approach, people get the the full flexibility of how they want to structure and implement their backend. And if they combine that with with a certain kind of web framework, such as Happy.js or uh Adonis.js, um even like maybe Keystone, do I- Uh, like Keystone.js to a degree. Um, then like GraphQL frameworks like uh Nexus or full-stack frameworks like Redwood.js and Blitz.js. These kinds of frameworks, they are kind of trying to find that sweet spot where somebody um can save like most of the plumbing that you would need to do, but at the same time still has the full flexibility on how they want to implement their their backend.

[00:18:42] Michael Chan: Interesting, interesting. You mentioned a lot of cool projects in there. And I think that, you know, RedwoodJS and BlitzJS, you know, they're doing some really cool stuff to try to, I guess, move that- move that sweet spot to, you know, code side, right? Which is really interesting. And I really like that approach. I think it's really exciting to see those things start to like start to form. I want to talk a little bit more about like kind of Prisma's role in all of this and like really flesh it out. Um especially especially now today, you know, there's been like a lot of like kind of historical steps, but how do you see Prisma in this kind of like new tech stack arrangement? Like where does it fit?

[00:19:26] Nikolas Burk: Yeah, so let's maybe continue where we like left off after we said that you have these two high-level options of a backend as a service and implementing your own backend. So like obviously when you're building your own backend, you will have to do a lot of coding yourself. And like on a high level, you have a couple of different choices to make there as well. And these choices are concerning the API layer. So you have to decide, okay, what kind of API should my server expose to the clients? And typically you have two choices there. That is a REST API and a GraphQL API. And like the GraphQL API approach is probably a little bit more modern and has a number of big advantages compared to REST as well. And like me, myself, I'm a big proponent and a big fan of GraphQL. And like I would just like use it uh like pretty much in any application where I use an API. I wouldn't even bother implementing uh like REST API routes. But on the other hand, I know that like this is really uh uh a matter of taste ultimately. Sure. There are a couple of good arguments for GraphQL and also for REST. And depending on your use case, um you might choose one over the other. But But one thing that I personally find really compelling about GraphQL, for example, is the fact that you have a schema for your API. Mm-hmm. And that I think has saved a lot of developer time already, just by the fact that you don't have to work with outdated API reference documentation, but the schema basically gives you an auto-generated uh documentation right there for your API and And like whenever you're talking to a GraphQL API, you basically know that you will have documentation for it and you know what kind of queries you can send, what input arguments you have to provide, and what you'll be getting back from the the API. And I think that's just a big, big benefit of of GraphQL compared to REST. But yeah, so like that's kind of the the first choice you have to make when you build your own backend, you have to pick the API layer and typically that's REST or GraphQL. And then you have to make a couple of more choices. For example, you have to choose which database do you want to use. Mm-hmm. And today, like most of the, or like still most commonly used database today are relational databases that have actually been developed already in the '70s. So SQL, the query language that is being used to query a relational database, has been developed in the '70s. And these databases are still kind of state of the art for modern applications. If you look at Postgres, I think uh it's by now kind of the the the most popular database uh like that's being used. And then you also have a couple of other like uh like MySQL or I think AWS Aurora, um a number of popular relational databases that you can choose from. So once you've made that choice also for what database you want to use, you now have to go and actually implement your backend. And no matter which approach you're choosing, whether you're using REST or GraphQL, in both approaches, you will need a way to talk to the database from your application code. So typically, if you're building a REST API, then you implement these uh like specific routes, right? You could have like a /user route, um or a /post route if you have sort of like a blogging application with users and posts. And um when these routes are- Are accessed from an HTTP request, when an HTTP request is being sent to that route, then um typically a a controller or like some sort of function is being invoked on on your backend. Yep. And in that function, you'll have to go and make sure that you're now fetching the right data from the database and that you package it up in the right format to be sent back to the frontend in the format that they expected.

[00:23:28] Michael Chan: Interesting. So, so, so, we have this kind of like programming language layer that is kind of like ripe for like maybe removing. Because a lot of times it's just- it's almost there. It seems a lot of times it can be easy to maybe- not easy. But that's a part where you would want to like abstract away. Because it's not necessarily doing a whole lot for you. Or it shouldn't be, right? Like a lot of times, you know, where big applications come into problems is when those layers are doing too much for you and you know the the work should be pushed off into either the client or the database, you know, for for speed.

[00:24:04] Nikolas Burk: Yeah, exactly. And I think um like a common problem to to tackle this as well, for example, in Express, is also to have middlewares, right? Like uh like middlewares are a concept that you'll find in a lot of server-side uh frameworks where you can kind of intercept the path of an HTTP request. Sure, sure. And you can kind of just like uh like make modifications or do data validation or anything like that. But what you'll still have to do ultimately is uh you'll have to talk to a database. And like what you're doing in these kinds of REST control— uh what you're doing in these REST controllers, the equivalent when using GraphQL is basically using your GraphQL resolvers. So like controllers and resolvers on that level are kind of similar. I mean, of course they are like on a high level still very, very different and different kinds of things, but you can imagine them having the same kind of responsibility in the backend and that they resolve the data that's being requested from the database and package them up to be returned to the client side. And uh when you're now implementing the the backend and you are at that stage where you have to think about, okay, how am I going to access the database from my server-side application? Then you typically on a very high level have 3 different options. And the the first option is It's kind of just plain old SQL. You- In that case, you would simply install a database driver in your application, and then you use that to kind of create a database connection or maintain a full connection pool to the database so that you can reuse connections. And you use these connections then to really just like send over these plain SQL strings to the database, and um the the data comes back in uh some weird shape that kind of uh like mirrors the rows and you just first have to extract the data that you were actually looking for. So this approach typically comes with a lot of kind of manual overhead that you have to do. And also, like it bears a lot of problems um like with respect to like safety actually, because it's it's so easy- Sure. When you're just submitting uh plain strings to the database, to just have a typo in there or like some other problem. You you just like couldn't re uh like properly remember the the name of a column that you wanted to retrieve the data for, and you just have a query that blows up at runtime. And that is certainly something that you want to avoid. So um like working with plain SQL strings in your application is is not really something that you would do. And if you do it, then you also typically just abstract it away in your own data access layer and you will build kind of the the functions that you can call inside a controller and you'll call out to that extra database access layer where the SQL is written uh once. But even with that approach, um you you still ultimately have the problem that you're writing plain SQL strings in your application and that I think is uh just generally something that that you want to avoid.

[00:27:11] Michael Chan: Yeah. Now it seems like the the industry solution to this, um you know, historically, has been kind of like what we've seen in in full stack frameworks, which is to have an ORM. Um or what what does that stand for? Object Relational Mapper?

[00:27:26] Nikolas Burk: Mapping. Exactly. Object Relational Mapper. Yeah. Or yeah, mapper. I think it's used for both.

[00:27:31] Michael Chan: And uh that seems to be like kind of the the the the tool of choice, I guess, in in that place to to say like, hey, I don't want to have to like recreate the world every time I want to get some data out of the database. Um and so, here's this tool that allows me to kind of talk about that more in like a code type of way. And those are very much like framework-specific. So tell me a little bit about about that part of it, the the the ORM part of it.

[00:27:58] Nikolas Burk: Right, right. So like we are effectively like climbing up the abstraction ladder, right? We are starting with plain SQL on the lowest level of abstraction, where we have to do a lot of work ourselves. It's the uh it's pretty much the same as if you were like writing C or assembly. You're operating at a very low level. Which means you have a lot of power, but with great power comes great responsibility. SQL is very very complex and so is assembly and C, and it's very easy to shoot yourself in the foot with these kinds of low abstractions. So climbing up the abstraction ladder a little bit, um what you'll find next are so-called uh SQL query builders. And these are um tools that already give you kind of a like programmatic way of formulating SQL queries. Um and like using those, you will still be writing SQL effectively, but you'll compose the queries programmatically. So instead uh so instead of writing a SQL string that's SELECT FROM the user table, you will call a function that's called select, and then in there you'll specify FROM the user table. Um so uh you you just get a set of functions basically that allow you to compose SQL queries. That's already a little bit better and makes you a little bit more productive, I would say. Mm-hmm. But it still has the problem that you basically have like really have to know and understand SQL um to to to be successful with that approach in a sustainable way. Sure. And uh that's where the next higher level of abstraction is coming in, object-relational mappers or ORMs. And the the characteristic property of these kinds of tools typically is that um they are trying to represent the tables in your database as classes in your object-oriented programming language. So the the mapping that takes place really takes place between a table, a relational table in your database. So like tables are the the main components, the main primitives of relational databases. And then in object-oriented languages, you typically define classes to implement the behavior of your application. And the idea of object-relational mapping is that you now define a class that maps to a table. So let's take an example again, like the user table, where you maybe have 3 columns with an ID, with a name, and an email field. So now you would just go and define a class inside of your application that also has these 3 properties. And what these ORM libraries typically give you is a way of storing and retrieving um data for these tables when you implement kind of their interface. So like like what they'll do often, they give you kind of like a a basic uh class that you can inherit from, like a model or an entity or something like this. And then you can implement your own user class, inheriting all the features from that model or entity class. And um that will allow you to perform data read and write operations on the instances of your own model class because you're inheriting from the superclass, basically from that model class. Sure. So with that approach, your model objects are typically kind of fairly blown up and and complex, even like really complex model objects where you implement the behavior for storage and retrieval of data. But at the same time, it's also often used as a place to add business logic. So for example, your user class could then have a method that just like validates an email or connects you with another user, whatever kind of business logic you have to perform in the context of a user, um like might be implemented in that class as well. But like I want to speak a little bit more about kind of the the the the fundamental problem of that approach in general. And whenever I do I just uh like reference back to an article that was written 15 years ago. It's called The Vietnam of Computer Science, written by Ted Nward. And it's kind of just like this uh very classical piece where he just explains the the problems of object-relational mapping. And the main problem, the fundamental problem with this is just that the the so-called object-relational impedance mismatch. So, so that's a complicated word. Uh, what it means is that the way how data is represented in your relational database and in your object-oriented programming language is fundamentally different. So the way how data is typically represented in your relational database is by means of tables. Um, and these tables, if they have relations with each other, they will reference each other through foreign keys. So the data is very flat. It's called normalized in like database terminology. Uh in in like in in database terminology. And you as the developer, you have to take care of kind of joining the data when you're retrieving data from the tables. So you're joining data from various tables. Sure. To get them into the structure that you need in your own application. And so that's the way how data is represented in relational databases and in object-oriented programming languages. And that's probably what most of the React developers uh like listening to this will be familiar with, is um that data is represented as objects. And these objects, they can be deeply nested. So you might have a user object, and inside that user object you have a posts key that lists an array of posts. And each of these posts- Right. Has another field uh where it lists all the comments. So like you can really nest the data inside of these objects arbitrarily deep, and this is just a model that is not possible in relational databases. And that's kind of the fundamental mismatch. Sure. And that's why the entire idea of object-relational mapping in that way is fundamentally flawed and um is not really something that uh like you wanna uh like build your application with. And on the long term can lead to like big, big problems if you're using uh like that approach.

[00:34:21] Michael Chan: Interesting. Now, there's a lot to- there's definitely a lot to unpack there because it's, you know, there's- I think for a lot of, you know, people listening right now, it's probably just sounding like like an unsolvable problem, right? Like if you haven't if you haven't had that experience of like kind of having to deal with all of these layers and you're like, I just want like like, I like I just want something that I can like query my data, you know, through like GraphQL and that's like kind of it. Like, um, feeling maybe like a little bit stuck because like you're like, okay, well, I guess I'm just gonna use, you know, some like off-the-shelf thing and just deal with the vendor lock-in. Um, so, I guess kind of like getting back to like solutions, like where is it— like where is it that Prisma fits into this? And like how do you see it as- Yeah. Kind of solving this problem, um, but without without the necessity to like really inform the way people are writing their code.

[00:35:18] Nikolas Burk: Right. So where Prisma fits into this kind of the abstractions that we talked about, I think it's probably somewhere between the SQL query builder and the object-relational mapper. So we call Prisma actually a query builder as well, but some people call it an ORM. Uh, like we're not really happy with with that kind of category uh categorization, and we actually have a page in our docs that explains like how Prisma is different from traditional ORMs. But it's also okay to call Prisma an ORM sometimes, uh because it really just explains how Prisma fits into your stack. So it really solves the same problem that an ORM would solve, or that a SQL query builder would solve, or even uh like writing plain SQL would solve. And that is just the problem of database access in general. Mm-hmm. It's really about the way how we are doing it that is different, but it's uh like solving exactly the same problem. And in fact, um one thing that is really compelling about ORMs and like one thing why a lot of people like to use them and only like learn about the problems later on in their journey is that it it gives you the the the programming model that you're already familiar with, right? Sure. As a developer, as an application developer, you don't have to think about your data in these relational terms that we discussed earlier, but really you can think of your data in objects. And that is what you're used to as an application developer. That's what you're working with all day. So ideally, that would be the kind of abstraction that you're using to talk to a database in your application. And it's kind of the same idea that we also discussed earlier with like writing plain SQL and then adding your own data access layer on top of that, right? You're rolling your own data access layer because you you want to be able to call functions that are doing the right thing for you. Yep. And that is exactly the the kind of idea that we are following with Prisma, is that we'll give you a number of uh functions that are auto-generated based on your database schema, and you can call these functions and you just get get plain JavaScript objects back into your application. And you have the full flexibility of describing these objects without having to to uh to do that in SQL terms. So you don't have to write uh joins or select statements, but you really can use the programmatic API that is provided by Prisma uh to to work with the data in your database and and store and retrieve data. Um Maybe making it uh concrete again by by means of that user model. So assume you have kind of the the user table in your database, and now you're not using an ORM where you create the corresponding class in your object-oriented programming language, but instead you're using Prisma. So the way how you would do that is if you already have an existing table, then you can introspect your database and generate a Prisma client for it. So like so at that point, I quickly want to mention that um with Prisma, we have three So what Prisma is in general, it's an open source database toolkit that really makes it easy for application developers to to work with databases. And it consists of 3 main tools. One is called Prisma Client. That's a database client or a query builder that you can use in your server-side application to read and write data in the database. But when you're using a relational database, um you're not only concerned with database access, but you're also concerned with creating and managing the schema for your database. And that's what we have a tool for that's called Prisma Migrate that will solve that problem. Mm-hmm. And that will allow you to define your database schema, your tables in a declarative way. And then Prisma Migrate will help you to map these declarative models that you define to your database by generating and sending the right SQL statements for you. So you really don't have to use any SQL anymore in that case, but rather you can just rely on like Prisma Migrate's approach here. Hm. And then we have a third tool that's called Prisma Studio. That's a GUI for your database basically, where you have quick access to the the the data in your database. You have like a table view where you can also easily connect and drill down into relations and um like have a lot of convenience just like visualizing your data. your your data. So yeah, you have uh uh these 3 tools and like right now we are like pretty much only talking about Prisma Client um in the context of accessing your your database uh uh on the server side. And the way how you would do that when you have the uh user table already defined is you can introspect the database and then generate Prisma Client um from that introspection result basically. And And like what it means to generate Prisma Client is that you, um like like so like what Prisma Client actually is, it's a it's a Node module that you install just like any other Node module in your application. You just do npm install @prisma/client and you get the Node module into your application. But the Prisma Client Node module is actually special. Uh it's a little bit special because is it only gets populated once you call the prisma generate command of the Prisma CLI. Um and what that will do, it'll read kind of your your data model and generate the code for that into that Node module so that you kind of have a custom or a smart Node module that you can then use inside of your own server-side application.

[00:41:09] Michael Chan: This is interesting. It's it's reminding me a lot of, like, you know, as someone who, Repeatedly, I keep saying this, like as someone who has like a lot of experience with Rails, um it's reminding me a lot of the things that Rails gets me in terms of controlling a database, right? Um which, you know, uh you'd mentioned like migration, also like access, you know, in this case, it's a little bit different because, you know, the access has to happen like on the client. Um uh but then also, like uh the the the defining things in terms of like a a a schema and then also your like migrations and being able to migrate without having to then like run those migrations as SQL queries yourself, which can be terrifying, I guess. Exactly. Maybe the best way to describe it. So, I I I'm it's really helpful for me like kind of in in that way to frame it as like, okay, this is like the the part of you know, the framework that that actually like connects you to data data, um you've now kind of like pulled out into its own service, I guess. Um so that now Prisma is that service that helps you with the migrations, the schema, like the database connection, um and does it in a way that allows you-

[00:42:25] Nikolas Burk: Exactly. I wouldn't call it a service, by the way. I would really just call it a library. Like a library that you're pulling into the code.

[00:42:31] Michael Chan: Okay.

[00:42:31] Nikolas Burk: Um so like service can sometimes have kind of like the Node of HTTP and like anything like this, like uh like what Prisma Client really is, just like a a library inside of your application.

[00:42:41] Michael Chan: Yeah, yeah, yeah. But then also like, so so it sounds to me like, if I understand correctly, like it doesn't necessarily matter where the data is coming from. Uh like you could, like you you you're not necessarily hosting all of the data for like everyone who's using Prisma, that can come from anywhere?

[00:43:00] Nikolas Burk: Yes, yes, absolutely. So when you're using Prisma, you're using your own database. You are going to use and you're going to host your own database. That could be a Postgres database on Heroku or DigitalOcean, uh like a MySQL database, could be a database on AWS RDS. So whatever database uh you you want to use, you can bring it basically and then you tell Prisma Client how to connect to it so that it can read and write the data in that database. So yeah, we're not at all concerned with hosting anything for anyone. Like really at this point, like what Prisma is, is just this open source database toolkit that you'll pull into your application as an npm dependency, but really no concern about hosting or or deploying anything from uh from our side.

[00:43:49] Michael Chan: Interesting, now that's a pretty big departure from, uh I I guess like where you started, I guess kind of going back to the the history side of things, things. Um, you know, the the first product that I was aware of that became Prisma was Graphcool. And that was kind of like an all-in type of thing. Like if you want to kind of one-click have a GraphQL database, um, that you can like start accessing and and sending data to, uh, that's Graphcool. And that has migrated pretty significantly to to where you're at today, where it's like you're you're not even like really hosting the data anymore.

[00:44:23] Nikolas Burk: Yeah, absolutely. I mean, like that entire transition um was— uh like I will say it was also like painful and frustrating for a couple of users because people really liked the tools at the time. And like understanding that the the tooling is still evolving because we are not kind of meeting our own requirements as to flexibility that we want to provide to our developers. and to the people using our tools, um, like we couldn't like really do that with with GraphiQL and neither with Prisma 1. Um, so like maybe talking uh uh a little bit about that history. Uh uh so starting with GraphiQL, we already mentioned that it's it's basically a backend as a service. And we also already kind of uh explained why we moved away from it, mostly because people liked it for prototyping, but it wasn't wasn't really kind of the- at the range of developers we wanted to serve. Like, we want the- Sure. The next generations of Twitter and Facebook and Airbnb to be built on our tools. And it's very unlikely that this is going to happen with a backend as a service, but rather these kinds of companies will always resort to building their own backends. So we wanted to give them a better abstraction of actually doing that and helping them by providing developer tools that they can integrate into their own applications. And so then we we pivoted to Prisma 1. And like Prisma 1, what it was basically, it was a a way to turn your database into a GraphQL API.

[00:45:58] Michael Chan: Okay.

[00:45:59] Nikolas Burk: And that GraphQL API, the special thing about that was that unlike you would expect, it wasn't supposed to be used from the frontend. Typically when a frontend developer sees GraphQL, they just think, okay, this is what I'll talk to, this is my layer, um and this is where I get my data from. This was not the case with Prisma 1. With Prisma 1, this was just basically a way to simplify database access on the application layer or on the API layer that you would still have to implement yourself. So we kind of turned the traditional 3-tier architecture into a 4-tier architecture where you had the database, the Prisma server, your API server, and the client. So you had 4 different kind of infrastructure components that you had to deploy and host yourself. And like it was great because um like people had an easier way of talking to their database on their API layer because they could use this convenient uh like GraphQL layer and- transform or actually like implement their own business logic, their own requirements on the API layer and have a very convenient way of of talking to the uh to the database. And they like didn't have to write SQL. And I think we at some point we kind of realized that like one of the the biggest benefits we provided to people was that we freed them from the need of thinking about their data in terms of SQL, but that we gave a really easy way to them to define their data and also to access their data. So the way how that worked with Prisma 1 was actually because it was all about GraphQL, you would define your database schema in terms of GraphQL SDL. So like GraphQL has its own schema definition language that is very easy to read and very easy to understand. And people just loved writing their database tables in that language and let Prisma 1 take care of then figuring out what the actual data uh uh like tables should look like in the database. But the the big problem was basic with like Prisma 1 was basically exactly that, that you had to host this extra Prisma server. Like like a lot of people like came to the conclusion that, okay, what Prisma ultimately does, it- Solves the same problem as an ORM, but I have to host my own server just to get an ORM. Like why like why would I need that? Why would I need the extra server to have an ORM? And that's when we kind of realized that the architecture that we had chosen for Prisma 1 with this extra Prisma server, which by the way ran on the JVM. So it was kind of heavy on memory consumption. Mm-hmm. And not that easy to just like to like monitor and and work with just in general. Like it was difficult. And like that's why we kind of realized, okay, we have to make this simpler. We want to solve the same problem. We want to give people the same ease of working with their databases, but we have to get rid of this extra component. And that's when we set out to rewrite Prisma to Prisma 2. We rewrote the core of Prisma actually in Rust, so that we have a very low-level component that can take care of, uh like, actually uh actually kind of ensuring that your database queries are being optimized. So- Mm-hmm. The the component of Prisma that's implemented in Rust is the query engine. And there we kind of implement our own query execution plan, our own query optimizations, uh like to make sure that you get the best performance for your database queries. And on top of that query engine layer, we then have kind of the wrapper for Node.js and TypeScript that then allows you to access the database through the query engine with Prisma Client. And I uh like think we don't have to to talk like that much about the architecture here. I just wanted to like mention it, but from a high-level perspective, you can really think of like Prisma Client just as a way of talking to your database in Node.js with queries that are completely tailored to your already existing database schema. And like one cool way about this that like we haven't touched on yet that I like for sure want to mention is the the type safety that you get with Prisma Client. How do you feel about type safety? Are you like a TypeScript user or- Like plain JavaScript?

[00:50:35] Michael Chan: Yeah, I mean, like, I uh I guess I kind of like uh waffle depending on, you know, what I'm trying to get done at the moment.

[00:50:45] Nikolas Burk: Fair enough.

[00:50:46] Michael Chan: Um, but yeah, I I really like I I really like TypeScript. Um, I've used it on a couple projects and um, I find that those are my favorite projects to go back to, um, because my thoughts about the project are codified into like the actual language. It's not comments that I have to remember. Like, like my thoughts are there in the code. And when I kind of violate those those thoughts or those principles, you know, coming back to it, you know, maybe, you know, months or a year or two later, um I'm I don't have to think as much, right? It's gonna remind me and I'm like, oh yeah, no, no, I decided that I, you know, this has to be that thing because of the other thing and oh, okay. And it kind of

[00:51:26] Nikolas Burk: A lot more sustainable, right?

[00:51:27] Michael Chan: Yes, oh, absolutely. And um, so yeah, so I'm I am a a a convert, I would say. I do like the the the current way of um the like incremental um typing, you know, that that's available in TypeScript. Um because it allows me to opt out in those times where it's like, you know what, I don't care that much.

[00:51:49] Nikolas Burk: I just need to get this thing out.

[00:51:50] Michael Chan: Yeah, yeah, totally.

[00:51:53] Nikolas Burk: Totally, totally. So I think that's spot on. And like um we at Prisma, like we really, really value type safety and we want to enable developers to have basically fully type-safe database access. So that you're sure that you can never mess up a database query at runtime, that all of your queries are always properly typed, the results of the queries are always properly typed, and you just can be sure that what you're getting there is just like type-safe. But I know that a lot of like plain JavaScript developers are not yet super familiar with TypeScript. And to be honest, it can be a little bit intimidating because like type safety is a concept that you just don't really find in in JavaScript. Compile-time type safety does not exist. Yeah. And like we go actually uh a long way to enable similar functionality similar benefits that you get with Prisma Client uh in TypeScript also for plain JavaScript developers. So if you're building your backend with Express and JavaScript and plain Node, not using TypeScript, you can still get a lot of the benefits that you would otherwise get uh when you're using TypeScript. And one big benefit is autocompletion. I think uh that that autocompletion in general is just a vastly underestimated kind of topic because it just makes you so much more productive. You don't have to go and look up API reference documentation anymore because you can just explore the API right there in your editor, kind of uh hitting Ctrl+Space and just like letting the editor suggest you what you can insert here. So I think this is just a killer feature that uh like makes developers really productive. And it was actually funny. I think you you recently had uh Chris on the show, like Chris on Code.

[00:53:45] Michael Chan: Yeah, yeah.

[00:53:46] Nikolas Burk: And um like he was on a on a livestream yesterday with my colleague, uh like Ryan Chenke. And-

[00:53:53] Michael Chan: Oh, cool.

[00:53:54] Nikolas Burk: They were going through Prisma Client and exploring kind of the the type safety features of it. And it was really nice to see kind of Chris' reaction to, oh, wow, wow, now I can just like uh hit Ctrl+Space and I see all these options. And like when you made a typo, it would just like yell at you and tell you, hey, no, like this is not possible here. So like I think the the type safety of of Prisma Client is really just worth mentioning. And uh you get a lot of these benefits, even if you're not using TypeScript, um which is really cool.

[00:54:25] Michael Chan: Awesome. Yeah, yeah, I love that. Um we'll definitely link that so people can watch, um you know, Chris on code actually like go through it. Um, because I I know a lot of people love watching his uh tutorials and lessons and livestreams. Um, now, unfortunately, we're kind of out of time. And I know that an hour is really not enough to talk about, you know, like, you know, the the history of databases, where they're headed, and and kind of where Prisma is like solving that. Um, but I thank you for your time and kind of giving us as much information as we can in the time that we have. How can people follow along with what Prisma is doing so that they can see if it's the right solution for them and just kind of, you know, give it a try?

[00:55:07] Nikolas Burk: Yeah, if you if you wanna learn about Prisma, I would just like recommend you to check out our website. We have a quick start that just lets you run through a very straightforward Prisma setup that uses SQLite. So no need for you to set up your own database server. We just have everything already prepared for you. That will give you a little bit of a taste for what Prisma is, how it works. And then you can like uh like dive a little bit deeper and like maybe connect it to your own database or or something like this. Um the the Prisma blog of course has a lot of uh like announcements and news around us as a company. And then we're also on Twitter. So just follow Prisma on Twitter to to be sure to to get the latest news.

[00:55:50] Michael Chan: Awesome, and how how can people find you?

[00:55:52] Nikolas Burk: So they can find me on Twitter as @nicholasburk. I'm also on GitHub as @nicholasburk. And if you uh if you want to reach out to me personally, you can also drop me an email um at burk@prisma.io. That's B-U-R-K at prisma.io.

[00:56:07] Michael Chan: It's very brave of you to share the email address.

[00:56:10] Nikolas Burk: Yeah, let's go. Let's see what people do with it.

[00:56:12] Michael Chan: I love it, I love it. Well, hey, thanks so much for your time today. I really appreciate uh your your kind of giving us a deeper insight into all the problems that need to be solved when figuring out that data layer and kind of talking about where Prisma fits into all that and uh how you're you're doing your best to help developers of really big applications. You know, not just prototypes, but like really big applications. Yes. So, I'm excited to see where you take this, where it goes, and uh kind of how how you can help out uh React developers and kind of making the next big thing.

[00:56:43] Nikolas Burk: Awesome. Yeah, thank you so much for having me. This was really fun.

[00:56:47] Michael Chan: This has been episode 106 of React Podcast with Nicholas Burke and Chantastic. For links, visit reactpodcast.com/106. Thanks to our sponsor, Infinite Red. If you have a project that's gone off the rails and needs expert help, get Infinite Red on your side. They've been designing, building, and shipping apps for 10 years and want to bring their expertise to your apps, products, and services. They have a deal right now where you get $750 for referring a new project. Get expert help from Infinite Red at reactpodcast.infinite.red. If you like this show, there's a fast, free way to demonstrate your support. Leave us a review on iTunes. It's the best way for you to let me know what you think we're doing right and what we can improve. 2 to 3 minutes of your time helps us make the best show we possibly can. As always, links and show notes for all episodes are available at reactpodcast.com. This episode was edited by Mikael Delport. It was produced by Mikael Delport and Sarah Jackson at Spec, a network to help you level up in design and development. Check out spec.fm for other shows that are sure to fast-track your career. I'm your friend, Chantastic. Thanks for listening. We'll be in your ears again next week.