Latest / Talk Python To Me / #355: EdgeDB - Building a database in Python
Transcript
- 0:00What database are you using for your apps these days?
- 0:02If you're like most Python people, it's probably Postgres SQL.
- 0:05If you roll with no SQL like me, you're probably using MongoDB.
- 0:09Maybe you're even using a graph database focused more on relationships.
- 0:13But there's a new Python database in town, and as you'll learn during this episode,
- 0:18many critical Python libraries have come into existence because of it.
- 0:22This database is called EdgeDB.
- 0:24EdgeDB is built upon Postgres and implemented mostly in Python.
- 0:29It's something of a marriage between traditional relational databases and an ORM.
- 0:33Python's async and await keywords, uvloop, the high-performance asyncio event loop,
- 0:39and asyncpg all have ties back to the creation of EdgeDB.
- 0:43Yuri Selvanov, the co-founder and CEO of EdgeDB, PSF fellow, and Python core developers
- 0:49here to tell us all about EdgeDB along with the history of many of these impactful
- 0:53language features and packages.
- 0:55This is Talk Python To Me, episode 355, recorded February 16th, 2022.
- 1:14Welcome to Talk Python To Me, a weekly podcast on Python.
- 1:17This is your host, Michael Kennedy.
- 1:19Follow me on Twitter where I'm @mkennedy, and keep up with the show and listen to past
- 1:23episodes at talkpython.fm.
- 1:25And follow the show on Twitter via at Talk Python.
- 1:28We've started streaming most of our episodes live on YouTube.
- 1:32Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming
- 1:38shows and be part of that episode.
- 1:40This episode is brought to you by Sentry and SignalWire.
- 1:43Use Sentry to find out about and fix errors when they happen and build real-time next-generation
- 1:49video meeting rooms with SignalWire's API.
- 1:52Transcripts for this and all of our episodes are brought to you by Assembly AI.
- 1:56Do you need a great automatic speech-to-text API?
- 1:59Get human-level accuracy in just a few lines of code.
- 2:02Visit talkpython.fm/assemblyai.
- 2:04Yuri, welcome to Talk Python To Me.
- 2:07Yeah.
- 2:07It's great to have you here.
- 2:08We just met recently at Pi Bay down there.
- 2:11So in honor of that, I wore my Pi Bay shirt today.
- 2:14Oh my God, I forgot about that episode.
- 2:17I probably should have worn my t-shirt.
- 2:18Yeah, where's your Pi Bay shirt?
- 2:20Yeah, yeah, yeah, yeah.
- 2:21What a cool conference, huh?
- 2:23It is.
- 2:24I love small conferences.
- 2:25I like small conferences.
- 2:26And in the time of COVID and all of this madness, having a winter conference outside in California
- 2:34at a beautiful food cart area where it's warm.
- 2:36Oh, there were just so many things to like about that.
- 2:39I got to tell you, it was great.
- 2:40It was amazing.
- 2:40It was the best day of the year for me, essentially.
- 2:44Just being able to talk to people finally and see many friends was amazing.
- 2:49We both gave talks there.
- 2:50I talked about Flask and HTMX.
- 2:52And you spoke about building a database engine, a whole database with Python.
- 2:57And that was interesting.
- 2:59So then I watched a little more and I just thought, wow, there are a lot of interesting pieces of
- 3:04technology in and around this thing you built called Edge TV.
- 3:08So I'm super excited to dive into that with you.
- 3:10But before we do, let's just hear your story real quick.
- 3:12How do you get into programming in Python?
- 3:14So my co-founder, Elvis, and I met many years ago, probably 14 years ago or something like that,
- 3:19working in a small Canadian company, building big enterprise software for companies like Walmart.
- 3:25Back then, we were actually like the system that we were working on was written in PHP.
- 3:31And I mean, we pushed PHP to the limits, but we always knew that, hey, when we start our own thing,
- 3:36we will be looking for something new and fresh for us to tinker with.
- 3:40And we looked around and we just like Python.
- 3:44Liked it a lot.
- 3:46Great syntax.
- 3:46Fantastic.
- 3:47Was that Django?
- 3:48I mean, that's right around the time of the Django growth or was it something else that brought you in?
- 3:52We started with Django.
- 3:54We played with it a little, but actually like we just started building our own thing pretty much
- 4:01immediately without looking like too deeply at existing frameworks or anything.
- 4:06Yeah.
- 4:06I get the sense that you and your co-founder are framework builders.
- 4:09Yes.
- 4:10Yes, we are.
- 4:11Somebody asked me, maybe it was Guido, I don't remember anymore.
- 4:13What was your first thing that you wrote on Python?
- 4:17And I said, the function decorator.
- 4:18I could just...
- 4:20John Trayden.
- 4:21Exactly.
- 4:22Awesome.
- 4:23So how about now?
- 4:24What are you doing these days?
- 4:25Working on EdgeDB full-time?
- 4:27EdgeDB.
- 4:28EdgeDB full-time exclusively.
- 4:31Yeah.
- 4:31We're building a great company here.
- 4:33So that requires 100% of my attention.
- 4:36Yeah.
- 4:36I bet it does.
- 4:37It's...
- 4:38You can build a business on the side, but it's a hard time.
- 4:42And you have this great article that talks about how you're going to build your favorite new database in a month,
- 4:48but that it actually takes 10 years.
- 4:49Do you like that, right?
- 4:51Yeah, pretty much.
- 4:52Yeah.
- 4:52It was a long, sometimes painful journey.
- 4:55And we didn't realize, like, right off the bat that we will be building a database, right?
- 5:01We were building a Python framework.
- 5:02And the Python ORM, essentially.
- 5:04And granted, that ORM was...
- 5:06Right.
- 5:06A better way to talk to databases in Python was your idea, right?
- 5:09Yeah.
- 5:10Yeah, exactly.
- 5:11But I guess you didn't have in mind that you would also build the database.
- 5:14No idea.
- 5:16Yeah.
- 5:16Very cool.
- 5:17Well, I think what you built is pretty interesting,
- 5:20and people are going to enjoy checking it out.
- 5:22But more so, I think what is pretty interesting is there's a lot of things in the Python space that we enjoy and we appreciate,
- 5:30especially what I would consider to be the advantages of modern Python.
- 5:35I don't know how you feel about it.
- 5:37I know you've been deep in this world.
- 5:38But to me, it seems like just two or three years ago, people building frameworks, you know, think FastAPI or Pydantic or stuff like that,
- 5:47have really embraced the...
- 5:50They've taken full advantage of Python 3, right?
- 5:52They said, oh, look, we have these typing, we have typing, we have ASIC and away.
- 5:55We have all these things that we can bring together.
- 5:56And it really feels like that stuff is all starting to come together in a big way.
- 6:00Is that over the last couple of years?
- 6:02What do you think?
- 6:02Yeah.
- 6:03I also have this feeling that the ecosystem becomes more and more robust, that people build amazing systems with Python.
- 6:09I think that asynchronous IO played a part in it for sure.
- 6:14But I think that the other big thing that is happening to Python right now is strict typing.
- 6:19mypy and the other similar tools.
- 6:23This is what actually allows you to manage your code base at scale.
- 6:27And this is just incredibly important.
- 6:30So yeah, those two things I would say.
- 6:33Absolutely.
- 6:33And you talk, we're going to get into it when we get into the architecture and stuff, but you talk about using Cython for making parts of your Python code faster.
- 6:40And of course, that relies heavily on typing.
- 6:43Because you want to say, here's an int 64.
- 6:44Don't turn it to a pi, you know, pi long object pointer.
- 6:49We just want an int 64 that works on the stack really quickly, right?
- 6:52Yeah, yeah, absolutely.
- 6:53I mean, it's an open question.
- 6:55Will Python ever enjoy strict typing that the Python interpreter actually takes care of to make things run faster or not?
- 7:04But for Cython, it's absolutely critical.
- 7:06And actually, I had this, sometimes I had this feeling that writing code in Cython is easier than in Python because, hey, I have a compiler.
- 7:13Something mismatches.
- 7:15I know it at the compile time, not the run time.
- 7:17Yeah.
- 7:17I suspect myPy is a little like that as well, right?
- 7:20Exactly, exactly.
- 7:21So when myPy started happening, because I was experimenting heavily with Cython before myPy became popular, when myPy finally became like this common thing to use.
- 7:30Yeah, it was almost a revelation that we finally have this beautiful workflow with Python.
- 7:34Well, I want to talk about some of the technologies that are sort of surrounding this larger project that you've been working on.
- 7:41So over on GitHub, github.com/magic stack.
- 7:45This is for, this is your company.
- 7:48And one of the, you know, where sort of EdgeDB and all that is coming out of.
- 7:53But there's a lot of interesting things happening here that I think people who see modern Python doing its thing are going to appreciate.
- 8:02We talked about the async stuff and so on.
- 8:05And so I wanted to kind of dive into some of those first that are sort of orbiting your projects that you all have created here.
- 8:12So let's start with Magic Python.
- 8:14Tell us what this Magic Python is about.
- 8:16So Magic Python is a syntax highlighter.
- 8:18It's actually used in VS Code by default.
- 8:21So if you use VS Code and you edit Python in VS Code, this is the stuff that VS Code uses under the hood.
- 8:27It was used by GitHub for years to highlight all Python code.
- 8:32And recently I think GitHub switched to this tree sitter other Python highlighter.
- 8:37But yeah, Magic Python was, and I guess is, incredibly popular.
- 8:42It was born out of frustration actually because we were big fans of metaprogramming.
- 8:47We abused Python a lot in interesting ways.
- 8:50And one of the ways to abuse it was to push some meta information to function annotations.
- 8:55It was before mypy and before typing.
- 8:58So yeah, we just were like adding stuff to those annotations.
- 9:02So we quickly discovered that built-in syntax highlighters in TextMate back then.
- 9:06Back then I was using TextMate heavily.
- 9:08They just couldn't highlight annotations.
- 9:10So my goal was to basically, hey, can we create our own syntax highlighter for Python that would just take care of annotations?
- 9:17And by the way, highlight all of the newer stuff that is available in Python 3.
- 9:22Because back then Python 2 was still the king.
- 9:25And Python 3 was kind of barely supported.
- 9:28Interesting.
- 9:28So a lot of the highlighters and editors and stuff really would highlight kind of based on Python 2 type syntax.
- 9:35Exactly.
- 9:36Exactly.
- 9:36But I guess.
- 9:37No, it's 20, whatever this was, in 2015 or something.
- 9:412015.
- 9:42Yeah, yeah.
- 9:42It was clear to me that Python 3 is the future.
- 9:44But yeah, the industry was still kind of moving slowly towards it.
- 9:48But the key innovation of Magic Python, and I think this is why I think it's a high quality thing, is unit tests.
- 9:56So I'm a big fan of writing tests and having this test-driven development.
- 10:02And the first thing after highlighting Hello World in TextMate, first thing for me was to figure out, can I actually build a unit test engine?
- 10:12Because if you think of those syntax highlighters, it's essentially, it's a huge reg exp.
- 10:17It's just mind-bogglingly, like huge, huge, huge reg exp.
- 10:21And writing reg exp is hard.
- 10:23Yeah.
- 10:25But modifying them is much harder.
- 10:28I was thinking about that.
- 10:28Well, I was thinking down the road, you have a really interesting query syntax that's pretty rich and powerful for EdgeDB.
- 10:36Yeah.
- 10:37Did your experience writing Magic Python give you the ability to go like, oh, yeah, we can write this thing that parses this insane sort of complex language?
- 10:46How much did this play into your ability to go beyond SQL?
- 10:50I wouldn't say much.
- 10:51I mean, we have syntax highlighters for our schema files and the EdgeQL.
- 10:55They're pretty basic right now.
- 10:56We just highlight keywords and literals.
- 10:59We have some interesting plans about that.
- 11:01And we can talk about that later.
- 11:02I guess we'll be talking about it to be like implementing language server protocol for EdgeQL.
- 11:07But the highlighter itself is pretty simple.
- 11:10But I used this unit testing framework in those highlighters.
- 11:15And this is what gives me peace of mind.
- 11:17I know that EdgeQL highlight is just working when I'm adding like a new operator or a new keyword.
- 11:22I don't have to just test it manually on some big file.
- 11:27Yeah, absolutely.
- 11:28Sort of speaking to that thing that I talked about, a lot of interesting stuff coming out of your work.
- 11:31Adrian out there says, didn't know you also made HTTP tools as well.
- 11:35Indeed, yeah, there's a lot of cool stuff that you've done.
- 11:38So final thing on Magic Python.
- 11:40Can I use it for other purposes than just VS Code, Sublime, and Atom?
- 11:44Like if I wanted to build my own thing that, you know, printed out like terminal stuff or like even some other kind of UI app.
- 11:52Could I use this more generally than the editors?
- 11:54I haven't tried it myself.
- 11:56But given that GitHub was using it to highlight the code, I believe that there must be some libraries and packages that just can consume this text-made inspired syntax and just highlight, I don't know, stuff you print into terminal.
- 12:10I see.
- 12:10So it comes out as text-made and then it just happens to these three editors with their...
- 12:14Yeah, I think...
- 12:15Sort of common heritage, understand that.
- 12:16Yeah, yeah.
- 12:17I think text-made started the revolution originally, then Sublime Text just inherited the format and then VS Code just decided, hey, we should just use it.
- 12:24Yeah.
- 12:25Cool.
- 12:26Yeah, very cool.
- 12:27All right.
- 12:28So when you spoke about your journey towards creating this product in this business, you talked about how central having asynchronous IO and server work is going to be.
- 12:41And of course that is true, right?
- 12:43Not all databases, but most databases are able to be a point of extreme concurrency to the point that they can handle the processing, right?
- 12:52So if you've got a web app, you can scale your web app out.
- 12:55And if it's got two connections or 200 connections to the database, generally, that's fine.
- 13:00The database is meant to sort of scale that vertically, I guess.
- 13:04So you really talked about, well, if you're going to do this in Python, that probably means leveraging asyncio pretty strongly, right?
- 13:10Yeah, yeah.
- 13:10It was pretty clear that we need asynchronous IO.
- 13:13As you said, databases have to handle lots of connections.
- 13:16And also it's important to understand that most databases like Postgres, for example, the cost of establishing a new connection is pretty high.
- 13:23So we wanted Edge.
- 13:26And I mean, there are tools to mitigate that.
- 13:28Like PG Bouncer, for example.
- 13:29It's like middleware you put in front of PostgresQL to make connections cheaper.
- 13:33And we just didn't want to have any of such tools as a requirement for Edge.
- 13:38We just wanted it to work like natively out of the box without any configuration.
- 13:42So yeah, we had to have cheap connections in terms of like how fast you can connect.
- 13:47And also, I mean, if your connection is just hanging out there, we wanted to allow that essentially.
- 13:52So we had to have a way to handle thousands, maybe hundreds of thousands, just concurrent connections that maybe are not super active, but just, I mean, open.
- 14:02And asynchronous core is the only way how you would be able to do this.
- 14:07Like not even like even if Python didn't have GIL, for example, you would still use asynchronous IO to tackle this problem.
- 14:14This portion of Talk Python To Me is brought to you by Sentry.
- 14:19How would you like to remove a little stress from your life?
- 14:22Do you worry that users may be encountering errors, slowdowns or crashes with your app right now?
- 14:28Would you even know it until they sent you that support email?
- 14:31How much better would it be to have the error or performance details immediately sent to you, including the call stack and values of local variables and the active user recorded in the report?
- 14:42With Sentry, this is not only possible, it's simple.
- 14:45In fact, we use Sentry on all the Talk Python web properties.
- 14:49We've actually fixed a bug triggered by a user and had the upgrade ready to roll out as we got the support email.
- 14:55That was a great email to write back.
- 14:57Hey, we already saw your error and have already rolled out the fix.
- 15:01Imagine their surprise.
- 15:02Surprise and delight your users.
- 15:04Create your Sentry account at talkpython.fm/sentry.
- 15:09And if you sign up with the code talkpython, all one word, it's good for two free months of Sentry's business plan, which will give you up to 20 times as many monthly events as well as other features.
- 15:20Create better software.
- 15:22Delight your users and support the podcast.
- 15:24Visit talkpython.fm/sentry and use the coupon code talkpython.
- 15:32There's an overhead for threads and the context switching between the OS trying to figure out if that thread still needs to do stuff.
- 15:38Yeah, you can't have hundreds of thousands of threads and be in a good place.
- 15:41Yeah, but my concern wasn't even that.
- 15:44Maybe we would be smart and implement some sort of M2 and scheduling or something like that.
- 15:49I don't know.
- 15:50It's just I don't believe that humans are good at writing threaded code.
- 15:54Async await gives you this luxury of essentially seeing where you can actually give up control.
- 16:02of the current code when it can await things and potentially switch the context, right?
- 16:06So you can be smart about locking access to shared resources and things like that.
- 16:10With threads, it's way, way harder.
- 16:13Maybe with Rust, it's easier because, I mean, there is some compile time magic that can help you.
- 16:19But with pretty much every other language, thread-based programming is very hard.
- 16:25It is hard.
- 16:26Well, I suspect many people, but not everyone out there listening knows that when you use the asyncio tasks and so on, at least by default, they run on a single thread.
- 16:38There's not actual threading happening.
- 16:40When you use threads or multiprocessing, you can get that true concurrency.
- 16:43But this is different.
- 16:45It's not really threads.
- 16:46Yeah, it's different.
- 16:47Basically, the idea for async await is to use it for IO bound code.
- 16:53So if your code is doing like lots of IO, pushing data from multiple connections here and there, this is an ideal thing.
- 16:59But if you're computing something like, I don't know, doing something, scientific computation or just use blocking IO or disk IO, it's best to offset that computation into a separate process.
- 17:12But yeah, if you just want to handle a lot of IO in Python concurrently, asyncio is the way.
- 17:18Yeah, the way that I like to think of asyncio and async and await is what you're scaling is you're scaling the waiting.
- 17:25If you're waiting on anything, if I'm waiting on a database or waiting in the database version for the client to talk to me or not to talk to me, then you can basically take that period where you'd be waiting and turn that into predictive computational time.
- 17:38I love it.
- 17:39I think we should put this like straight into the ducks.
- 17:41I've never thought about this week.
- 17:44Because people tell me, I'll see these benchmarks and stuff said, oh, well, I did this thing where I overwhelmed the database and then it didn't go very fast when I did asyncio.
- 17:53It's like, well, because there's no period in which you're waiting.
- 17:56Like you're like constraining the resource beyond what it can take.
- 18:00But if there was some sort of, oh, I'm waiting for this thing to get back to me.
- 18:03Well, then all of a sudden there's your performance.
- 18:05Okay.
- 18:06So when I saw this come out, I was super excited.
- 18:09I think this was 3.4.
- 18:10My history reminds me correctly when this came out.
- 18:14Is that, do you remember?
- 18:15I think it was around 3.4 because the most important prerequisite.
- 18:19I think so.
- 18:20Because 3.5.
- 18:21Yeah, go ahead.
- 18:21Sorry.
- 18:22Yeah, the most important prerequisite for asyncio to happen was actually the yield from syntax.
- 18:26Probably not a lot of people remember about it.
- 18:28But back then, asyncio required this like add-corting decorator and you would use yield from instead of await in your code.
- 18:35So that PAP, so basically Python 3.3, I think, was a moratorium on modifying Python language.
- 18:42So we had to wait for Python 3.4 to add yield from and then asyncio happened.
- 18:46We made it happen.
- 18:47Right.
- 18:47That enabled it.
- 18:48But when I remember when it came out, I was like super excited about this.
- 18:51And I said like, oh, this is a harsh programming model.
- 18:54This is really like direct and juggling those sorts of things.
- 18:59And I had experience with C#, which had async and await keywords as well.
- 19:05I'm like, gosh, I wish this language had async and await.
- 19:07And then I didn't know you then, but I thank you because you authored PEP492 coroutines with async and await.
- 19:15Basically, we have async and await in Python because of you, right?
- 19:18Well, somewhat.
- 19:19Yes.
- 19:19I don't want to give you too much credit.
- 19:21I did.
- 19:21You created the PEP that said like, let's stop using yield from and continue and all these other things that you do.
- 19:28I can tell you the entire backstory.
- 19:30It's relatively short.
- 19:31Yeah.
- 19:31Yeah.
- 19:32So basically we were trying to figure out like the future API for HDB, Python client back then when HDB wasn't doing a thing.
- 19:41And we knew that we want to support asyncio in our future client.
- 19:47But how do you actually have like a migration block?
- 19:49Like you would have to say like try, finally accept, back, commit.
- 19:53It's like a lot of code.
- 19:54And we have context managers in Python, right?
- 19:56So with the context manager, you would just say with transaction and just do all this magic behind the scenes.
- 20:02But we didn't have an asynchronous version of with.
- 20:05We had yield from.
- 20:07But how do you kind of mush together yield from and with wasn't clear.
- 20:12So I thought, hey, if we have like async keyword, we could have async with.
- 20:16Then it was natural case.
- 20:18We just should replace yield from with await because it was also familiar with C#.
- 20:22And I also liked the short and neat syntax of async await.
- 20:26And then the next thought was that, hey, what if you have a cursor to the database and just want to iterate over the rows and make it like prefetch those rows.
- 20:34And this is how async four was born.
- 20:36And then in about a couple of weeks, language summit happened.
- 20:39I think it was in Montreal.
- 20:40That was back on US in Montreal.
- 20:43And I met with Guido.
- 20:45I showed him like rough sketch and he said, yeah, let's do it.
- 20:48I think I implemented the first prototype of this thing in the interpreter over a couple of nights.
- 20:54Like I just called it like straight 48 hours.
- 20:57I wanted to impress Guido.
- 20:59And yeah, I just had this like rough implementation.
- 21:03And then just over the course of like months and a half, I was refining it and writing this path.
- 21:08And this is how it happened.
- 21:09I think it all happened because of Guido.
- 21:11Because first of all, he saw like clearly like this is an improvement to Yulthrom, like a big improvement.
- 21:16It's a huge improvement.
- 21:17It makes it incredibly approachable.
- 21:19It's like you do what you normally do, but sometimes you might have to put the word await there.
- 21:22Exactly.
- 21:23But your mental model isn't about callbacks and weird stuff like that.
- 21:27It's just like you write the regular code, but you sometimes need to await a thing.
- 21:31And it's beautiful.
- 21:32Yeah, exactly.
- 21:33Exactly.
- 21:33And yeah, I'm grateful to Guido because first of all, he recognized this thing and encouraged me.
- 21:38And second of all, he actually like inspired lots and lots of refinements in this proposal.
- 21:43And I was like working with him essentially all this time.
- 21:46Like a discussion happened in Python, in Python dev.
- 21:49And sometimes he and I exchanged emails and he proposed some ideas and I would just tweak the path.
- 21:53Yeah, Guido was actually also behind this proposal to a big extent.
- 21:57There's some mind-blowing stuff here, like the async with, for example, as you point out, right?
- 22:02These are wild ideas, right?
- 22:04Instead of just calling, just saying here, there can be a function.
- 22:06You have async for, async with.
- 22:08There's really neat things in here.
- 22:10Actually, yeah, I think that still async with is pretty unique.
- 22:15Like JavaScript, for example, is lucky because they have this nice syntax for declaring anonymous functions, right?
- 22:21And so you can just say await transaction and pass a function.
- 22:26And it's like a multi-line function.
- 22:28You can do whatever you need.
- 22:29You don't actually have to have something like async with in TypeScript or JavaScript.
- 22:34But in many other languages, you would need something like this.
- 22:38And pretty much, I think, we pioneered this idea in Python.
- 22:43I think I saw a proposal to make using async in C#, but I'm not actively engaged with C# community.
- 22:49So I'm not.
- 22:50Maybe it was implemented.
- 22:51Maybe not.
- 22:51I don't know.
- 22:52That would be the parallel, but I'm also not tracking it.
- 22:55Yeah.
- 22:55Okay.
- 22:56This is really cool.
- 22:57So awesome, awesome work on this PEP and getting this language.
- 23:00Thank you.
- 23:01Thank you.
- 23:01Yeah.
- 23:02So let's talk two more async I think real quick here before we get to EdgeDB.
- 23:05Or actually, three.
- 23:08One jumped the list just yesterday.
- 23:10Absolutely.
- 23:11Okay.
- 23:11So when you're doing asyncio, there's this background event loop that looks at all the things that could be done and says, are any of them waiting?
- 23:20Can we take that while it's waiting and put it aside and go do something else, right?
- 23:25That way I scale the waiting story.
- 23:27And there's an implementation for that in CPython.
- 23:29But you all decided, you and Elvis, your co-founder, decided it would be nice if there was a faster, more optimized version of that part that does the checking and execution.
- 23:41So you created this thing called uvloop, an ultra fast asyncio event loop.
- 23:45It's incredibly easy to use, right?
- 23:47Like to install it.
- 23:47Two lines.
- 23:48It's two lines, right?
- 23:50You import and then you run install and you're good to go, which is fantastic.
- 23:55Tell people about uvloop and how broadly, should this just be standard stuff we do in all of our code that uses async and await?
- 24:03That's an interesting question.
- 24:04Okay, let's jump in.
- 24:05So uvloop wasn't the first thing that I created.
- 24:08The first thing was actually HTTP tools.
- 24:11Someone asked you about it like a few minutes ago.
- 24:13So I just wanted to experiment with Cython.
- 24:16I discovered Cython.
- 24:18I thought, hey, this might actually be a useful tool and allow us to speed up Python a lot for some things like parsing HTTP, for example.
- 24:26Right.
- 24:26The tight loops.
- 24:27Yeah.
- 24:28Exactly.
- 24:28Exactly.
- 24:28So I look at Node.js and they used a C HTTP parser.
- 24:33I think that parser was actually extracted from Nginx.
- 24:36And yeah, just wrapped it in HTTP tools.
- 24:40Just literally like 100 lines of code, maybe even less, maybe 50.
- 24:43Just like a small wrapper over the C library.
- 24:47And it worked.
- 24:48And it worked great.
- 24:49Then I, oh my God, I now have this superpower.
- 24:52I can quickly.
- 24:54What other things can I grab and wrap up and put it into PHP?
- 24:56Exactly.
- 24:56Exactly.
- 24:56Because, I mean, you could do the same, but just like using Python C API, but you would end up writing like 3x, maybe 5x amount of code.
- 25:04And using Cython just feels like magic.
- 25:06So, yeah, it worked.
- 25:08And then I was like, hmm.
- 25:10Interesting.
- 25:11Interesting.
- 25:11So there is this libuv library that actually powers Node.js and it's cross-platform.
- 25:16And it's super fast and Node.js is fast.
- 25:19Maybe, just maybe, I can do the same.
- 25:23I can just wrap it into Python and make a drop-in replacement for it eventually.
- 25:27So I prototyped something relatively quickly.
- 25:29Maybe in a few days.
- 25:31Basically, I just implemented like a loop object and call soon.
- 25:34Like, basically the staple of ACKIO.
- 25:37The most basic thing.
- 25:39And it worked.
- 25:40It worked just fine.
- 25:41I was able to implement call later.
- 25:42And then I was able to run a coroutine like, await sleep one, print hello world.
- 25:47And it worked.
- 25:48And then I just, over the course of next several months, I think three, maybe four, maybe five months.
- 25:54I was gradually implementing AsyncIO API.
- 25:57I swearing a lot because I discovered that this API surface is just huge.
- 26:01AsyncIO event loop is just, it's an enormous API actually.
- 26:04And yeah, then we, we posted benchmarks and I think it went somewhat viral.
- 26:11It was in HN.
- 26:13I think it was like post number one on HN for a long time.
- 26:17Yeah.
- 26:17I think Brian and I covered it over on the Python Bytes podcast when it came out because it was, it was big news.
- 26:22Yeah.
- 26:23Yeah.
- 26:23Yeah.
- 26:23Yeah.
- 26:23People are excited specifically because basically we showed that you can write some Python code, like a simple protocol parser, and it would be almost as fast as Go.
- 26:33And sometimes it's on faster than the Node.js, which was surprising.
- 26:38So yeah, I think a lot of people were excited about it.
- 26:41Yeah, that's fantastic.
- 26:41So the quick takeaway here is uvloop makes AsyncIO two to four times faster.
- 26:47You've got some benchmarks for different situations and amount of data and so on with regard to sockets.
- 26:52So let's wrap this one up with, is that a universal statement that you would recommend there?
- 26:57UV loop.install?
- 26:59It depends.
- 27:00I think for production, it makes a lot of sense to use uvloop or you should try it because I mean, there are still some minor incompatibilities in uvloop.
- 27:07That are really hard to track.
- 27:09Maybe there is some behavior difference, or maybe there is a box simply using something that a lot of people are not using with uvloop.
- 27:15And it's still a possibility.
- 27:18So yeah, use it, use it with care in production.
- 27:21In local development, I don't think you need it.
- 27:23Like vanilla AsyncIO should be, should be plenty.
- 27:25There is one more interesting thing about uvloop.
- 27:28It's a package.
- 27:29It's a package on PyPI.
- 27:31So if we find the bug, we fix it and we publish a package.
- 27:35You don't have to wait until Python 3.11.7 to get your bugs fixed.
- 27:40Or improvements made.
- 27:41Yeah.
- 27:41Or improvements made.
- 27:42Exactly.
- 27:43So this kind of suggests that it's a great idea to use uvloop.
- 27:47But on the other hand, we really haven't had like any emergency releases or anything in a long time.
- 27:52We basically release almost like every year just to catch up with the latest Python version.
- 27:57I would say that uvloop is pretty stable at this point.
- 28:00Yeah.
- 28:01Very cool.
- 28:01Yeah.
- 28:02It definitely seems neat.
- 28:03I think also it's probably a context of when does it make sense, right?
- 28:06If you're running three tasks and that's your whole program, who cares how fast the event loop is?
- 28:12All right.
- 28:12It's three tasks.
- 28:13But if you have many, many fine grain, tons of little tasks and there's lots of, like how complex and how many tasks,
- 28:20like basically how complex is the task coordination job of asyncio, right?
- 28:24The more complicated it is, probably the better benefit you'll get from uvloop.
- 28:28What do you think?
- 28:28If you go deep in the details, I would say it's not so much about juggling tasks around.
- 28:34It is more about performing IO in the most optimal way.
- 28:38Okay.
- 28:38And LibUV is just because it's so low level.
- 28:41It just uses lots and lots of tricks under the hood to just do IO faster.
- 28:46And the entire loop of like calling callbacks in the loop is just,
- 28:50it's a tight loop in C essentially.
- 28:52So it's much faster than a loop in Python.
- 28:55So that actually, yeah, those two points.
- 28:57But yeah, the performance improvement is noticeable usually.
- 29:01Very noticeable with the uvloop.
- 29:03Cool.
- 29:03The benefit is if it's literally import uvloop, uvloop dot install.
- 29:07Yeah.
- 29:07Run your benchmarks.
- 29:09Comment that line out.
- 29:10Run your benchmarks again.
- 29:11Exactly.
- 29:12Exactly.
- 29:12It's so easy to, you don't have to commit to it.
- 29:14It's not like, oh, we're going to swap ORMs and try it again.
- 29:17Exactly.
- 29:17Yeah.
- 29:17But I just love packages in Python that do this magic.
- 29:21Like if you remember, there was this package called psycho created by Armin Grigo, creator
- 29:26of PyPy.
- 29:27You just import psycho, psycho install or something like that.
- 29:30And boom, you have like an alternative CPython eval loop.
- 29:34Your program just magically becomes five, ten times faster.
- 29:37It's just magic.
- 29:38So yeah, it's great when we can do something like this.
- 29:41Yeah, that's fantastic.
- 29:42Adrian has an interesting question.
- 29:44I know this came up around requests a couple years ago.
- 29:47He asks, could you give your thoughts on having things as part of the standard library?
- 29:51Basically having uvloop in this case be part, you know, be the replacement for asyncio loop
- 29:58rather than having an external package updated independently.
- 30:01Yeah, it's an interesting question.
- 30:02And I'm not super involved in conversations like this.
- 30:04I know that Python core developers consider it actually separating standard library
- 30:08and shipping of them aside so that it can have like its own release schedule.
- 30:12I think it's sort of mitigated with Lukasz Lang actually speeding up the release cycle for
- 30:17Python now.
- 30:18It's being released like every year, which is amazing.
- 30:21And I think the pressure is lower now to separating standard library.
- 30:24As far as including uvloop as part of standard library, I'm not sure it's a good idea.
- 30:29First of all, it's entirely in Cython.
- 30:32It's like 50,000 lines of Cython or something like that.
- 30:34We will have to either adopt Cython as like an official standard library tool or rewrite it in C.
- 30:41And if you rewrite it in C, it's going to be 100,000 lines in C or something like that.
- 30:45It will be huge.
- 30:46So probably not going to happen anytime soon.
- 30:49Maybe with things like mypyc, we can make it happen eventually.
- 30:54Yeah, that's interesting.
- 30:55But mypyc is still pretty early.
- 30:56Right.
- 30:56Okay.
- 30:57Yeah, the conversation was had around that with regard to requests as well.
- 31:02Maybe you're even part of it since you're a core developer.
- 31:05But they decided not to make requests the new HTTP library of CPython because it would hobble requests.
- 31:13Like it would mean requests could only be changed, you know, once every 12 months or something like that.
- 31:19Right?
- 31:19Yeah, I think one of the concerns with requests specifically, and I wasn't actively involved in those conversations at all.
- 31:25But I think the concern that I heard was that HTTP is pretty wild and you often need to fix some security issues and bugs and you need to act quickly.
- 31:36And if something as huge as requests and so fundamental as requests was part of standard library, we would just have to be like way more flexible about making bug releases for CPython.
- 31:49But Python is just, it's such a huge thing, right?
- 31:53Like operating systems bundle it, like multiple different workflows are centered around it.
- 31:59It's just...
- 32:00It runs on helicopters in Mars.
- 32:02I mean, come on.
- 32:03Exactly.
- 32:03There's a lot of edge cases.
- 32:05People are not thinking about it.
- 32:06Exactly.
- 32:06Just upgrading a separate library is so much easier than upgrading the entire Python thing.
- 32:11So, yeah, I think this is why packages like requests for sure will stay out of standard library.
- 32:17Yeah.
- 32:17All right.
- 32:18Final question before we move on from uvloop, because it's not even our main topic, but it is very interesting.
- 32:23Teddy asks, are there any trade-offs of using uvloop as opposed to the native built-in one?
- 32:30I think this is time for me to make a shout out because we still haven't implemented a couple of APIs that are in AsyncIO, like API balls protocol.
- 32:41Maybe there is something else.
- 32:43I just haven't got time to do it myself.
- 32:45We are busy with SGB.
- 32:47So if anyone wants to join the project and help, that would be great.
- 32:50And that basically answers the question.
- 32:52The fundamental APIs are already all there.
- 32:55It's almost 100% compatible with uvloop.
- 32:58No...
- 32:58With vanilla AsyncIO.
- 33:00No trade-offs except there are a couple of relatively new APIs, I think path 3.9 and path 3.10 that are still missing from uvloop and that we still should implement them.
- 33:11Yeah.
- 33:11To be a true replacement, right?
- 33:13Yeah.
- 33:13I think it's sent file and API balls and maybe something else.
- 33:17Okay.
- 33:17UV loop is running inside EdgeDB?
- 33:20Yeah.
- 33:21It powers the IO server.
- 33:24Basically we use multi-processing architecture in EdgeDB.
- 33:28We have a pool of compiler processes because this is like computation CPU heavy thing to compile your query.
- 33:36And then there is a core IO process that just runs uvloop and quickly, quickly, quickly goes through your connections and pushing data between clients, posts, etc.
- 33:48This portion of Talk Python To Me is brought to you by SignalWire.
- 33:51Let's kick this off with a question.
- 33:52Do you need to add multi-party video calls to your website or app?
- 33:56I'm talking about live video conference rooms that host 500 active participants, run in the browser and work within your existing stack, and even support 1080p without devouring the bandwidth and CPU on your users' devices.
- 34:09SignalWire offers the APIs, the SDKs, and Edge networks around the world for building the realest of real-time voice and video communication apps,
- 34:17apps with less than 50 milliseconds of latency.
- 34:20Their core products use WebSockets to deliver 300% lower latency than APIs built on REST, making them ideal for apps where every millisecond of responsiveness makes a difference.
- 34:30Now, you may wonder how they get 500 active participants in a browser-based app.
- 34:34Most current approaches use a limited but more economical approach called SFU, or Selective Forwarding Units,
- 34:40which leaves the work of mixing and decoding all those video and audio streams of every participant to each user's device.
- 34:46Browser-based apps built on SFU struggle to support more than 20 interactive participants.
- 34:52So SignalWire mixes all the video and audio feeds on the server and distributes a single unified stream back to every participant.
- 34:59So you can build things like live streaming fitness studios where instructors demonstrate every move from multiple angles,
- 35:05or even live shopping apps that highlight the charisma of the presenter and the charisma of the products they're pitching at the same time.
- 35:12SignalWire comes from the team behind FreeSwitch, the open-source telecom infrastructure toolkit used by Amazon, Zoom, and tens of thousands of more to build mass-scale telecom products.
- 35:22So sign up for your free account at talkpython.fm/signalwire, and be sure to mention Talk Python To Me to receive an extra 5,000 video minutes.
- 35:31That's talkpython.fm/signalwire and mention Talk Python To Me for all those credits.
- 35:38So another thing that came out just today, I know this is, I don't want to spend too much time on it, but there's a big new feature for tasks and async.io in Python 3.11 coming very soon.
- 35:51And you just gave a shout out on Twitter yesterday saying that task groups is coming to async.io.
- 36:00This is a way, because right now if you start two tasks, there's no way to say, well, if this one fails, don't even bother running that one, right?
- 36:07They're fully independent.
- 36:08This is a way to sort of create a dependency and control them as a set, right?
- 36:12Tell us real quick about this.
- 36:14I have an API for spawning tasks concurrently.
- 36:17It's called async.io gatherer, but it's just a suboptimal API in many ways.
- 36:22And this API is like way superior.
- 36:25We have to credit Nathaniel J. Smith for his work on Trio and Trio Nursery specifically.
- 36:31And Trio is, I mean, we can run an entirely different podcast episode just about Trio and async.
- 36:36I actually had Nathaniel on, yeah, we talked about Trio on the show quite a while ago when it was fairly new.
- 36:41It's an amazing thing and there are lots and lots of great ideas in Trio.
- 36:44One of them is having this thing, it's called nursery in Trio and the async and the task groups,
- 36:53async.io task groups, essentially, they just replicate this nursery idea.
- 36:56They port it from Trio to async.io.
- 36:59Like the bigger points about how this API works are all similar to Trio.
- 37:04There are some details about how constellation works, et cetera, but most people probably won't really care about that one.
- 37:10Yeah.
- 37:11Okay.
- 37:12Very cool.
- 37:13It's great to see more innovation.
- 37:14Yeah.
- 37:15And the async.io.
- 37:16Yeah.
- 37:17But task groups, I'll just talk for a couple more minutes about task groups.
- 37:19So task groups was like a more requested thing.
- 37:22A lot of people wanted task groups in async.io.
- 37:25And I was DMed like, sometimes I was DMed like on a daily basis entirely.
- 37:29Like we promised us task groups.
- 37:31When can we have our task groups?
- 37:32So the big like elephant in the room with task groups is how do we handle exceptions?
- 37:37Because multiple things can fail at the same time and the essential will propagate out of this async with task group.
- 37:43You'll end up with a hierarchical tree of exceptions.
- 37:47Exactly.
- 37:48And we just had to figure it out.
- 37:49And we had to figure it out in the core because if it was just some, I don't know, some exception class defined in async.io, then what would happen when you, when your async.io program crashed?
- 38:02Right.
- 38:03You wouldn't have like a correct state, a trace back in your terminal.
- 38:06You wouldn't be able to understand what actually happened.
- 38:09So we had to integrate this into trace backs and like a debug.
- 38:13We needed to make sure that it's like a standard thing that tools like Sentry, for example, can take advantage of it and provide you like great visibility into what happens in your async application.
- 38:23So we had to work in this exception group thing.
- 38:26And there's this amazing new core developer, you read CatRiel and she spearheaded this effort of just implementing this and drafting a proposal and just doing it to completion essentially.
- 38:42And it's because of her work, actually, task groups are finally a thing because task groups themselves, it's like 100 lines of code.
- 38:49There is with comments, there is not much to them.
- 38:52The huge thing is getting exception groups in.
- 38:55And I believe Python is the first language that has this feature, like right in the syntax, right in the runtime model.
- 39:03And this is also huge because I actually believe that Python now can be like one of the best languages to do concurrent programming.
- 39:10And I don't know, maybe when we have JIT or something like that, it might actually match a goal in performance somewhat.
- 39:16Yeah.
- 39:17Would be ideal thing.
- 39:18So while I'm looking at this syntax here, which I'll try to quickly simply communicate to people listening on audio.
- 39:24It's an async with block.
- 39:25So what you do is you'd say async with asyncio dot task group, and you create this task group and then you can create tasks within there that are all grouped together.
- 39:35And then you also can do things like await stuff while you're in there.
- 39:39It looks to me like one of the things that often I don't see possible in Python's async.
- 39:46Previously, it's the ability to just fire off a task and have it sort of just run in the background to completion.
- 39:55So you don't have to do like async or like run all or gather or any of those types of things.
- 40:00Basically, the width block, we won't exit the width block until all the tasks are finished or until it fails.
- 40:07One of those two, right?
- 40:08Yeah.
- 40:09That's a cool feature of it alone to just kind of say like, I don't need to kind of store up all the tasks and then make sure I'm waiting on them forever.
- 40:15Like I can just kick them off and then like if they happen to start in this place, then they're going to finish when this width block finishes.
- 40:22I'm even more excited about this than I was before.
- 40:24Right, right, right.
- 40:25It's a nice API to compose things in asyncio.
- 40:28And I believe it's one of the bigger deals in the recent years.
- 40:34So I'm super excited about this.
- 40:353.11 is out soon.
- 40:37Exactly sure the release date.
- 40:38I know it's in alpha stuff right now.
- 40:40So it's getting real near.
- 40:41Yeah, yeah, it should be should be close.
- 40:43Yeah, for sure.
- 40:44Awesome.
- 40:45All right.
- 40:46Last thing before we get to EdgeDB proper people.
- 40:49I would say that Postgres is the most popular database for Python people doing database things, possibly with the exception of SQLite.
- 40:56But that really counts for just like, oh, I'm doing testing or oh, I use this for this incredibly small, but like production level stuff.
- 41:03Got to be Postgres, right?
- 41:04Yeah, yeah.
- 41:05It's fair to say.
- 41:06Yeah, maybe throw in some MySQL and then like a little bit down, maybe some MongoDB, something like that.
- 41:11But like, clearly, it seems like Postgres has a lot of interest for folks.
- 41:16If you want to talk to it through async and await, which is exactly how you want to scale your database stuff.
- 41:24A pretty popular library is this one called asyncpg, right?
- 41:27Yep.
- 41:28Yep.
- 41:29Yeah, you and Elvis created that, huh?
- 41:30Yeah.
- 41:31So yeah, it was an interesting experience.
- 41:33Basically, we knew that the EdgeDB will be based on Postgres.
- 41:37That was clear.
- 41:38They won.
- 41:39And we also knew that we have to have like this very high performance bridge, essentially, between Python and Postgres.
- 41:48And it had to be asynchronous.
- 41:50So there was no good asynchronous client for Postgres back at the time.
- 41:56And we couldn't just use PsycAPG, the most popular Postgres driver, because it uses text encoding for data.
- 42:03Maybe not anymore, but it used to have text encoding.
- 42:08And we actually had to use binary for something.
- 42:11So we just knew that, okay, we have to just jump in and explore Postgres protocol.
- 42:15And we decided, okay, let's write the driver.
- 42:18Yeah, this is how Async PG was born.
- 42:20And I think what makes Async PG different, just besides that it implements binary protocol and it's asynchronous, it's API.
- 42:27Because we were not basing it on the common Python DB API.
- 42:32We basically designed an API to be as low level as possible, as close to Postgres semantics as possible.
- 42:39So in DB API, there is this thing called cursor, which has nothing to do with the actual database cursors.
- 42:44So we didn't want to replicate that.
- 42:46So yeah, we just built like what we thought were proper primitives, working with Postgres as efficiently as possible.
- 42:53We used binary protocol plus Async I/O.
- 42:57And we of course use Cython to speed up like all the bottlenecks in it.
- 43:01It's pretty much entirely in Cython actually.
- 43:03And yeah, the result is just amazing to this day.
- 43:07Async PG is like one of the fastest Postgres clients on the planet across all languages.
- 43:13That's fascinating.
- 43:14You can see that it beats Node.js and go pretty handily there.
- 43:18Yeah, we should probably update this chart actually.
- 43:20I'm pretty sure that they updated PG library for Node.js.
- 43:23So this is outdated.
- 43:24I think it's closer in performance to Async PG, but I think Async PG is still the fastest.
- 43:30Yeah.
- 43:31Cool.
- 43:32Awesome.
- 43:33So taking all these together, uvloop, Async and await in the language, Async PG, all of these are building up your skills to sort of almost build a database.
- 43:43And so then you went on and actually did build a database, right?
- 43:46Yeah, pretty much.
- 43:47So we had this framework, which was like almost an arm in Python for many years.
- 43:51And we built multiple different production applications with that.
- 43:54We shipped applications that were deployed to GE, Cisco companies like that.
- 43:58And we knew it's something interesting, but we also knew that it has to be bigger than just a Python or like it has to be a database.
- 44:07It's a surprisingly long road to make something to go this path essentially, because you have to define a query link.
- 44:15You have to define type system, you have to define standard library, you have to define protocols, how it works, how migrations work, all the different syntaxes for schema modeling.
- 44:24It's a huge thing.
- 44:25And yeah, with like all the right primitives in Python itself, we knew that we can start like morphing our code base into like this separate service essentially.
- 44:36And yeah, that was the necessary and required groundwork to make HDB happen.
- 44:41Without it, we would probably not succeed.
- 44:44Cool.
- 44:45So HDB really written in Python?
- 44:47It is.
- 44:48Mostly.
- 44:49Yeah.
- 44:50Mostly.
- 44:51Entire like IO service server is essentially a Cython thing.
- 44:54So it's in C and this is why if you look at benchmarks of HDB, it's actually pretty close to Postgres, to vanilla Postgres.
- 45:02Like the overhead of HDB is super low.
- 45:04That is only possible because of Cython and like all low level tips and tricks that we learned when we were working on uvloop and the asyncPG.
- 45:13So we really optimize it a lot.
- 45:15Yeah.
- 45:16The compiler part, the thing that actually takes an HQL query and compiles it to SQL, that thing is pure Python and that runs in a separate process.
- 45:24But we do some also tricks to make it fast.
- 45:27Like we cache things aggressively.
- 45:29I mean, in most applications, you don't have thousands of queries.
- 45:32You only have like 10, 50, 100.
- 45:35Yeah.
- 45:36So they get cached pretty quickly and then you don't even run Python anymore.
- 45:40From that point on, it's just C.
- 45:41Oh, interesting.
- 45:42Yeah.
- 45:42You don't need to incredibly optimize the understanding of the query because like you said, it's not ad hoc stuff happening that happens at scale.
- 45:52Exactly.
- 45:53Exactly.
- 45:54I mean, it's great when your compiler is exceptionally fast, but for a database and especially if it's smart around extracting constants, let's say you send a select one and then your next query is select two.
- 46:06Essentially it's the same query.
- 46:07Substitute the same query, just different constants.
- 46:09So if you extract it and you cache the file query as if this wasn't the constant, but the argument the query, then yeah, you don't need to compile it for the second time.
- 46:17So yeah.
- 46:18Yeah.
- 46:19I don't know Postgres super, super well, but I know some databases, they at their level, when they see a query, they're like, oh, I've seen this query before.
- 46:28They can cache the query plan and those types of, so that's like another level of performance and speed up as well.
- 46:34Right.
- 46:35We do that as well.
- 46:36I mean, we did it even in async Pg, for example, async Pg automatically prepare statements for you to enjoy this optimization.
- 46:43So that Postgres doesn't have to reparse or SQL query can just execute the precast plan.
- 46:48We do the same in HDB and many other things.
- 46:51This is why HDB is kind of, it's based on Postgres, but it fully envelops Postgres because we want to be in like full control on the underlying Postgres instance.
- 47:00Right.
- 47:01So in some sense, this is a brand new database that's got some really cool features that I'm going to ask you about.
- 47:05very soon.
- 47:06Absolutely.
- 47:06But in the other sense, it's got a lot of stability because it's kind of a database level API rethinking of a well known core that people already trust.
- 47:15This is an interesting thing.
- 47:16Actually, a lot of people are not 100% satisfied with relational databases for a variety of reasons.
- 47:22Somebody.
- 47:23Yeah.
- 47:24Somebody is not satisfied with scaling.
- 47:28Some are not satisfied with SQL and some not satisfied with migrations and how rigid the schema is and how inconvenient it is to deal with the relational database.
- 47:38And so it's a huge problem.
- 47:40You have a part of it, which is just language design and by standard library and type system, how that part works.
- 47:46The second is workflows around your database.
- 47:48The third is the engine of your database, like how it actually works.
- 47:52EdgeDB wants to challenge everything, but we also not dumb enough to challenge everything.
- 47:59At the same time, we understand that just writing this whole thing from scratch is impossible.
- 48:05No company in the world would be able to pull it off.
- 48:07Well, maybe some companies would be able to, but they're definitely not a startup.
- 48:11But they have many, many employees.
- 48:13Exactly.
- 48:14And they're probably public.
- 48:15Giant tech companies.
- 48:16Exactly.
- 48:17So for us, the only viable strategy was to pick a database that is already trusted, that is already fast and universally loved, which is Postgres.
- 48:28And it's also incredibly capable and just build on top of it.
- 48:32And it's not actually a new approach in databases.
- 48:34Like lots of databases actually are built on like primitive key value databases, like level DB or something like that.
- 48:41It's a popular approach.
- 48:43We're just taking it further.
- 48:44We are saying that, hey, using a key value storage won't buy us much.
- 48:49We are like high level programming language requires a lot of code to be written to properly be executed in good time.
- 48:57But SQL looks like this nice compile target.
- 49:01So this is why we use Postgres.
- 49:02Yeah.
- 49:03Very cool.
- 49:04Kind of the TypeScript to JavaScript equivalent of the database query language in a sense.
- 49:08Yeah, pretty much.
- 49:09I mean, sometimes I explain HDB as LLVM.
- 49:11Like imagine LLVM, it compiles your high level code to low level code and then it, et cetera.
- 49:17And the same about HDB.
- 49:19We compile your, like high level schema to like a proper normalized table layout.
- 49:24We compile our HQL, high level query language down to SQL.
- 49:28SQL and that SQL can actually be jittered by Postgres.
- 49:31So essentially, ultimately your HQL might be executing with like at native code speed, not now, but in the future.
- 49:38So what's the elevator pitch for people who are out there?
- 49:42They're slightly, you know, not super thrilled about the database they're necessarily using, whatever that is.
- 49:47And they're kind of exploring.
- 49:49I picked up a few things that I think make it unique, but I want to ask you, it's your baby.
- 49:54All right.
- 49:55I guess I'll give two pitches.
- 49:56One is super high level and one is slightly more low level.
- 50:01A super high level pitch is that imagine you have a tool and when it's a great tool, it becomes an extension of your hand.
- 50:08Essentially, you just don't notice it.
- 50:10You just do things, right?
- 50:11Current databases are not like that.
- 50:13They require lots and lots of mental overhead to work with them.
- 50:18Like what one library do you use in this language?
- 50:21Right.
- 50:22Is there lazy loading and N+1 stuff I got to consider or is it not and all those kinds of things?
- 50:26Exactly.
- 50:27And then you have to learn their API and then you have to learn SQL and understand how those things interact with each other.
- 50:33And then you have to care about deployment and migrations.
- 50:36It's just so much headache.
- 50:38This alone explains why MongoDB was so popular and is so popular because a lot of people just decided, okay, to hell with that.
- 50:45I don't want to deal with this.
- 50:46I believe in the relational space altogether.
- 50:49Yeah, exactly.
- 50:50Just abandoning this train.
- 50:53Yeah, and we want to fix all of that in HDB.
- 50:57We want to give you a tool that you just don't notice.
- 50:59We want to give you a data model that just feels native to Python or TypeScript or Go or any other language.
- 51:06You don't have to think in tables anymore.
- 51:08I want to give you a query language that is super easy to use and learn and compose and build query builders around.
- 51:16And essentially we want to essentially kill the entire concept of ORM.
- 51:21We don't need it anymore.
- 51:23We are almost sorry that ORMs have to exist in a way.
- 51:28I was going to ask you about that.
- 51:29There are so many incredibly difficult problems.
- 51:31This problem is called object impedance mismatch there.
- 51:33Yeah.
- 51:34And tables to like objects.
- 51:35It's a super hard problem.
- 51:37I feel sorry that they have to go through this.
- 51:39But we just looked at this problem and decided, hey, can we actually just solve this object impedance problem in a different way?
- 51:47Can we just avoid solving it entirely?
- 51:49Can we just give you a database with the proper high level data model that doesn't have this problem at all?
- 51:54Sure.
- 51:55And then suddenly you don't need ORMs.
- 51:56Let's talk real quick about the actual way you define what would be the equivalent, I guess, of a DDL table create script or somewhat related to that maybe closer is like an ORM class.
- 52:08Like it's kind of the...
- 52:09Okay.
- 52:10Can I start a little from afar?
- 52:11Yeah, yeah.
- 52:12Let's start back.
- 52:13Okay.
- 52:14Now it's going to be the second pitch, which is slightly more detailed.
- 52:17So we say that HDB is a new kind of database.
- 52:20It's not just relational.
- 52:22We call it a graph relational database.
- 52:25Essentially, we are saying that we created an extension to the relational model.
- 52:30So what actually constitutes the graph relational model?
- 52:33It's first of all, in all of your like rows, all of your tuples in your relational algebra, they essentially have a globally unique key.
- 52:43Now, this is a requirement.
- 52:44So data independent is just UID essentially.
- 52:47Every row in your database will have it.
- 52:50This is the first requirement, first modification.
- 52:52The second extension is links.
- 52:55The idea that links between data is like a first class citizen of the model.
- 53:00You don't need join, you don't need foreign key.
- 53:02You just know that, hey, if this type links to another type, it's just going to be like a relationship between the unique IDs.
- 53:09This is what unique IDs gives you.
- 53:11And the second thing is the third thing is that everything is a set.
- 53:15This, like if you have an object that is connected to multiple other objects, this is a set of objects.
- 53:25If you have an object that has a bunch of properties, then a set of properties.
- 53:29Even a single thing is a set as well.
- 53:31And this later enables HQL to be super composable.
- 53:35But these are just like three simple kind of axioms that are in the core of the model.
- 53:40So if you, if we talk about like this schema snippet where we have an object type, a block post with required property content, which is text and required link author, which is another type called user.
- 53:54It's going to be compiled to a table in SQL with a column called content with a column ID, which is going to be a unique UUID for every blog post that will have it automatically.
- 54:05It's immutable.
- 54:06It's read only.
- 54:07You don't have to create them manually.
- 54:08And a user will also be a table and also have IDs.
- 54:13And then we'll have a separate column, which is going to be called author, which you will have IDs of users.
- 54:19So ultimately, ultimately like deep beneath what you see in edge DB is like this high level schema.
- 54:25It's all compiled properly for the relational model.
- 54:28It's all normalized there.
- 54:30We are still relational.
- 54:31We still like exhibit like the same, the same characteristics as just, we're hiding a lot of this like low level things.
- 54:37that you had to bother with with this high level model, just abstracting away the low level stuff.
- 54:44Is there a way to directly connect to that relational view?
- 54:48You mean Postgres, the underlying Postgres other ways?
- 54:50Yeah.
- 54:51Yeah.
- 54:52Like the underlying.
- 54:53I'm not sure even that's necessarily a good idea, but you know, like in SQLAlchemy, there's a way to go like, I just need to get out of here and send raw SQL for a moment.
- 55:01Right?
- 55:02Like that feels like that's kind of the same.
- 55:04I just need to go to the guts for a minute.
- 55:05Yeah.
- 55:06Yeah.
- 55:06Yeah.
- 55:06Yeah.
- 55:07Yeah.
- 55:07So with edge DB, the goal is for you to never actually need that.
- 55:10There is just one exception to this.
- 55:12Just one exception.
- 55:13Ideally.
- 55:13Yeah.
- 55:14Okay.
- 55:14But basically our goal with edge QL, like we knew that first of all, we have to elevate the data and make it more high level.
- 55:21And second of all, we knew that, Hey, order for a relational database to be successful, it just has to have query language.
- 55:28Right.
- 55:29And because our data was different.
- 55:31We have to come up with our own.
- 55:32This is how which kill was born.
- 55:34Yeah.
- 55:34And we spent years designing edge QL.
- 55:37And the reason why is because we wanted it to be actually more powerful than SQL in many ways.
- 55:44Basically, if you have something that is expressible in SQL, but isn't expressible in SQL, we treat it as a bug immediately.
- 55:51If something is easier to do in SQL, it's a bug.
- 55:53And this is why we spent so many years kind of refining this thing to make it to be capable of thing.
- 55:59So basically you never need to use SQL.
- 56:02You don't need to know about SQL or know about its existence.
- 56:05And this is a powerful thing because when you use a norm library, you have to know about SQL.
- 56:10With SGP, no, you just learn one language.
- 56:12You're good to go for the rest of your life.
- 56:14Essentially.
- 56:15There's just one use case when you might need SQL.
- 56:18It's when, let's say you're a big company and you're using some BI tools like Tableau or something like that.
- 56:26Graph analysts that already know SQL.
- 56:29And we're going to do something about it.
- 56:30We're going to open like a special adapter.
- 56:34Adapter.
- 56:35Exactly.
- 56:36We'll allow you to just run SQL against the database in read-only mode.
- 56:39That makes a lot of sense.
- 56:40Because there are these tools, these big BI tools.
- 56:42And you're like, if your data is here, do you really want to like have some job to move it to another Postgres just to run an analysis on it?
- 56:49Yeah.
- 56:50Exactly.
- 56:51I mean, just like with us not attacking this problem all at once and implementing the engine and the language and everything.
- 56:56else here, we also understand that we are not going to replace all the business intelligence infrastructure overnight.
- 57:03Yeah.
- 57:04And yeah, we have to make it be compatible.
- 57:05It's not there yet.
- 57:06We'll be a part of a future release.
- 57:09Eventually.
- 57:10You'll have a nice roadmap, which we'll cover in a minute.
- 57:12But like, I really love that.
- 57:13Oh my God.
- 57:14Don't do it.
- 57:15Don't do it.
- 57:16Don't do it.
- 57:17I can just say it out loud.
- 57:18Like the ideas that we have.
- 57:19But let me, like just for people who want to see if they go there, just visually, the way that you've laid this out of like where you are and where you're going.
- 57:26Like so many libraries and products should model this because so often, you know, you'll reach out to the companies.
- 57:33Hey, it'd be great if you could do this.
- 57:34Oh yeah.
- 57:35It's on our roadmap.
- 57:35Like, oh yeah.
- 57:36Well, what is that?
- 57:37Like some, where do you even have this?
- 57:38Anyway, I think your roadmap is great, but give us the update.
- 57:41It is, it is beautiful and I encourage everybody to go and check it out.
- 57:44It's hdp.com/roadmap.
- 57:46It's, it is slightly outdated.
- 57:47Well, lots of things that are in progress were already done.
- 57:50Yeah.
- 57:51This formula car here, this is a 2021 series.
- 57:53They just redid the Formula One cars for 2022.
- 57:56So yeah, that's probably not what you're talking about.
- 57:58Yeah.
- 57:59All right.
- 58:00So tell us what's coming for this.
- 58:01What's coming.
- 58:02It took us years for building HDB 1.0.
- 58:04And during this time, we were almost encouraging people not to use HDB because it's a relational database.
- 58:10If you build a business on an alpha version of relational database and goes down, your business will go down with it most likely.
- 58:16And people should know you just released 1.0, right?
- 58:18Yes.
- 58:19That's a huge, huge thing.
- 58:20Congratulations.
- 58:21We launched 1.0 a week ago.
- 58:22It was on Hacker News, number one for like 13, maybe 14 hours.
- 58:27Wow.
- 58:28It was a pretty, pretty interesting event.
- 58:29We also had a live stream, us launching it, talking about architecture of HDB, of the query language, comparing it to SQL.
- 58:36It's a great event and I encourage you to check it out if you have a live stream.
- 58:39If you're interested, it's YouTube/HDB.
- 58:42Check it out.
- 58:43You'll find it there.
- 58:44But yeah.
- 58:45So it took us years to do 1.0 just right.
- 58:47To make sure that SQL is right, that its design is sound and that the schema is right and the workflows and CLI and the cloud APIs.
- 58:56Everything is just right and that we are confident that, hey, we're not going to be changing it.
- 59:00We're not going to be retroactively fixing things.
- 59:02Took us a long year, many years, but now it's out.
- 59:05And now we don't want to spend many years on HDB 2.0.
- 59:09We actually want to make it way quicker.
- 59:11We have the solid foundation.
- 59:12We can iterate much faster now.
- 59:14And this is what we're going to do.
- 59:16So our current target, internal target, is to release 2.0 sometime in May 2022.
- 59:22So relatively soon.
- 59:242.0 will have a few features.
- 59:27One is almost implemented.
- 59:29It's a group by statement.
- 59:31As I said, the idea of HQL is to actually surpass SQL in capabilities.
- 59:37And right now with HQL, it's already incredibly powerful.
- 59:41You can fetch that data hierarchies.
- 59:43You can compute things.
- 59:44You can use aggregate functions.
- 59:46You have sub queries.
- 59:47You have JSON.
- 59:48Like it's an incredibly powerful language right now, but a proper group by statements will give it like proper analytical flavor.
- 59:56Now you will be able to actually create reports and we have a great group by design.
- 1:00:00By the way, we try to make HQL design process as open as possible.
- 1:00:04We have RFCs.
- 1:00:05It's a github.com/HDB slash RFCs.
- 1:00:08So if you're interested to look at how our group by is different from SQL group by and why it's better than SQL group by, you can just go ahead and read an RFC about our group by.
- 1:00:18So group by is going to be one thing.
- 1:00:20The second thing is going to be a proper explain for your queries.
- 1:00:23Like why is my query slow?
- 1:00:25We have some ideas on how to make it less critic than the default explain output that you get most databases.
- 1:00:31Then there is an exciting thing.
- 1:00:33And I hope that we'll have enough time to implement it, which is access control.
- 1:00:38So HDB is this like vertically integrated thing.
- 1:00:41So you define your schema and in your schema you can define aliases, which is basically a view in your relational database.
- 1:00:49You can define fields or object types that are computed dynamically with that scale.
- 1:00:54So schema depends on SQL and SQL depends on schema in HDB.
- 1:00:58They are intertwined.
- 1:01:00So we have this idea.
- 1:01:01It's not that it's like super new, but in HDB it's going to be super powerful.
- 1:01:06Is that you'll be able to specify different policies on your schema type.
- 1:01:11Like allow reading something or allow mutating something or disallow, etc.
- 1:01:16Right.
- 1:01:17And we don't want to hard code that.
- 1:01:19So essentially we are introducing this concept of context in a database.
- 1:01:23You'll be able to define sort of like global variables, like context variables in your schema, say a user ID in 64 and something else.
- 1:01:33And then when you just get your connection in your Python code, you say with context plus user ID that is automatically passed to the database.
- 1:01:43In your schema, you can implement arbitrarily access logic on your schema type.
- 1:01:49And this logic will be automatically enforced in order of queries.
- 1:01:52So fantastic.
- 1:01:53Yeah, that's really cool.
- 1:01:54Fetching data for the home page is filtered.
- 1:01:55You are fetching data for report and it only includes the data that your business logic allow it to be there.
- 1:02:02So basically with HDB, you will have schema and that schema not only will define just the data layout of your application, but also the access patterns and many other things in the future.
- 1:02:13Yeah.
- 1:02:14I really want to ask you about the query syntax.
- 1:02:17Yeah.
- 1:02:18I find it super interesting, especially also how it relates to like ORMs and so on.
- 1:02:24But Michael out in the audience has a pretty neat question that sort of follows on to the roadmap first.
- 1:02:29So since HDB is fundamentally Python, it'd be great to have a way to run user defined functions in Python, I guess, still like stored procedures, but Python.
- 1:02:40Yeah.
- 1:02:40Not SQL.
- 1:02:41Yeah.
- 1:02:42Yeah.
- 1:02:42Yeah.
- 1:02:43It's an interesting question.
- 1:02:44I mean, user defined functions.
- 1:02:45Well, first of all, there are like a couple of different planes, I would say, of user defined functions in the context of HDB because HDB has this notion of extensions.
- 1:02:54The API isn't public yet, but HDB, for example, supports GraphQL natively.
- 1:02:59You can just run HDB, let's say on port 555.
- 1:03:02This is the localhost:555/db/mydb/graphql.
- 1:03:07We want you to be able to also define potentially, eventually, like user defined API handlers there so that with HDB, you would not need a backup at all if your business logic is relatively simple and you don't need like a full blown application.
- 1:03:24Oh, interesting.
- 1:03:25So if I've got like something on Netlify where it's pure static code, I just write a little JavaScript, some view or whatever, and it could theoretically do read only stuff maybe to an HDB.
- 1:03:36To an HDB instance or something like that.
- 1:03:38Or even write only.
- 1:03:39Yeah, absolutely.
- 1:03:40We just want to kind of push this idea of backendless development as far as we can.
- 1:03:46And because HDB has this incredibly powerful schema and will soon have access control, that already allows you to eliminate a lot of code, right?
- 1:03:53If only you could define some simple server side, database side functions.
- 1:03:58A little bit of Python in there.
- 1:04:00I'm starting to come around.
- 1:04:01Yeah.
- 1:04:02A little bit of Python or JavaScript or maybe a Rust or something.
- 1:04:05that you can just make that request to Stripe API, do something and then glue things together.
- 1:04:10Yeah.
- 1:04:10Then maybe you don't need the backend at all.
- 1:04:12So this is our vision eventually to allow things like this.
- 1:04:16And second plane is user defined functions within the database.
- 1:04:20And because there is in Postgres, those functions are going to be running like inside Postgres.
- 1:04:23You will be able to call them from the query language.
- 1:04:25Like, hey, use NumPy to crunch this data for me.
- 1:04:29Like write in SQL.
- 1:04:30This is also possible.
- 1:04:31There are extensions for Postgres that allow you to do that.
- 1:04:34It's possible to define user defined functions in Postgres.
- 1:04:38Multiple different extensions for that are there.
- 1:04:41So yeah, it's an interesting thing for us to think about.
- 1:04:45And we are thinking about it, but probably not for 2.0.
- 1:04:48Yeah.
- 1:04:49Okay.
- 1:04:50Very cool.
- 1:04:51So let's take this statement here for a minute.
- 1:04:52Yeah.
- 1:04:53This query syntax highlights a lot of probably what makes EdgeDB unique and some of your motives
- 1:05:00here.
- 1:05:01So this, if you wanted to go and get say a movie, which has a relationship to an actor's
- 1:05:07table and you want to do some sort of filter type thing, you would say select movie curly
- 1:05:13brace, look at that title.
- 1:05:15That's the select projection.
- 1:05:16So a movie.title basically.
- 1:05:18And then actors, curly brace, name and email.
- 1:05:22So is that, is this part right here, this, the sub actors, is that traversing the relationship,
- 1:05:27that graph relationship?
- 1:05:28Exactly.
- 1:05:29You're basically traversing the graph.
- 1:05:30And then inside the select statement, you say order by.name and you have this cool convention
- 1:05:34of dot, which if you're in one of these scopes, like curly bracket actors, then you can say
- 1:05:41dot and it means dot name applies back to actors that, right?
- 1:05:44Actors.
- 1:05:45Yes.
- 1:05:46And basically this is just syntax sugar.
- 1:05:47Nothing prevents you from spelling it out completely.
- 1:05:49Like you say, you can say order by movie.actors.name.
- 1:05:52Yeah.
- 1:05:53But because you're already in inside the actors, essentially, we're just like giving you this.
- 1:05:57Yeah.
- 1:05:58Fantastic.
- 1:05:59Then another thing that stands out for the query syntax is you can define inline variables
- 1:06:03using the walrus operator, by the way.
- 1:06:05Yeah.
- 1:06:06So you can say average review equals math mean dot reviews of the movie, then dot rating.
- 1:06:13And is this also traversing?
- 1:06:15Exactly.
- 1:06:16What is this?
- 1:06:17Yeah.
- 1:06:18a movie type has a multi-linked reviews.
- 1:06:23So multiple reviews can be attached to movies and every review has, let's say five star rating,
- 1:06:28an integer one to five.
- 1:06:30And this is how you quickly can say, hey, just calculate the mean number of all linked reviews
- 1:06:36and all their ratings.
- 1:06:38So somebody on Hacker News years ago aptly called HGL as a child of SQL and GraphQL.
- 1:06:43And I mean, it's funny, but there is truth to it because GraphQL made it extremely obvious
- 1:06:50to people that working with object hierarchies this way, when you can just have a query that
- 1:06:55just select something deep, right, is extremely important.
- 1:06:58People suddenly realize this is cool.
- 1:07:00Some companies have been trying to make GraphQL work for relational databases such as Hasura.
- 1:07:05And they have an amazing product.
- 1:07:06The only problem is that GraphQL isn't actually, it wasn't, it wasn't designed for creating databases.
- 1:07:11It's an API language, it's a REST replacement.
- 1:07:14So while it works for some things, good luck computing something in GraphQL.
- 1:07:18You just can't, you can fetch things, but you cannot compute like your average review is,
- 1:07:22is not possible to do in GraphQL.
- 1:07:24SQL on the other hand is, is very stubborn when you have to select anything nested, like
- 1:07:31things in tables, you have to think in tables, you either like select super wide tables,
- 1:07:35and then you have to write some Python code to kind of combine it back to your shape or use
- 1:07:40a norm, or if you use an advanced database, you can things like, you can use things like
- 1:07:45a Reag, but SQL isn't, isn't, it doesn't shine for things like this.
- 1:07:49So with, HQL, we're kind of marrying those both worlds.
- 1:07:53You have this, deep fetch syntax and, you have an ability to drop computation in any,
- 1:08:00at any point of your query.
- 1:08:02Now a couple of other like super important things about HQL.
- 1:08:06If you want, I can go into them.
- 1:08:08Yeah.
- 1:08:09We're getting short on time, but yeah, go ahead.
- 1:08:10Sure.
- 1:08:11As I said before, sometimes the pitch HDB is like this LVM thing, like,
- 1:08:14compiler.
- 1:08:15When we compile HQL query to a SQL, we have one important thing.
- 1:08:19Every HQL query, no matter how complex it is, it's always compiled to just one SQL query.
- 1:08:25And this is very important in the context of relational databases, because when you have
- 1:08:29just one single query, it's atomic.
- 1:08:31So you don't need like an explicit transaction.
- 1:08:33You're already like working.
- 1:08:35You always work with the same snapshot of the essentially.
- 1:08:37Interesting.
- 1:08:38So you're not in this case, like going, doing a query for the movies and then doing a query
- 1:08:42for the actors and then doing a query for the reviews as three steps.
- 1:08:48You're just, it's basically a three way join.
- 1:08:50And then you're getting the data back out.
- 1:08:51Something like that.
- 1:08:52It's slightly more complicated than three way join.
- 1:08:55Yeah, sure it is.
- 1:08:56But yeah, basically, basically, yeah, that's, that's the idea.
- 1:08:59We wouldn't, for one HQL query, it's always one SQL query.
- 1:09:01It's very important.
- 1:09:02We use lots of interesting tricks to make it happen.
- 1:09:04And if you're interested about those tricks, YouTube slash HDBs and watch our live event,
- 1:09:08we explain this all actually.
- 1:09:10But it's an important thing.
- 1:09:11And then HQL is actually, it's very composable.
- 1:09:15So you can pack multiple different queries into one query.
- 1:09:18So you can have a query that reads data, insert data, mutates data, and introspects the schema.
- 1:09:24All in one huge thing.
- 1:09:26And it will execute quickly for you and return your data like in proper way, ready for you to be consumed.
- 1:09:32So HQL is extremely powerful in that regard.
- 1:09:34This is what separates it from ORPs because your OR, be it SQLAlchemy or Pre-Ur,
- 1:09:39or Prisma or something like that.
- 1:09:41They might have a high level API for some operations, but they also don't really restrict themselves
- 1:09:47on how many queries it will take to implement that API.
- 1:09:50Right.
- 1:09:51And sometimes N plus one.
- 1:09:52Yeah.
- 1:09:53Right.
- 1:09:54And if you benchmark it on localhost, for example, databases on your laptop and your code
- 1:09:57executes on laptop, it appears to be fast.
- 1:10:00So you have three queries instead of one.
- 1:10:02So what?
- 1:10:03Like there is zero latency between your database and your code.
- 1:10:05And probably not full production levels of data.
- 1:10:08Sure.
- 1:10:09But when you move it to the dot data center, you will have latency between your code and
- 1:10:13the database.
- 1:10:14And even if you have like one millisecond latency between your queries, suddenly you just start
- 1:10:19losing performance a lot because your Python that uses or JavaScript that uses a norm operation,
- 1:10:26you can actually fire like 10 queries.
- 1:10:28This is easy.
- 1:10:29Like 10 queries is fine.
- 1:10:30And imagine it just spend 10 milliseconds on just doing that.
- 1:10:34Yeah.
- 1:10:35Just latency.
- 1:10:36Nothing else.
- 1:10:37Yeah.
- 1:10:38Just losing performance.
- 1:10:39So with SGP, it's not a thing.
- 1:10:40All right.
- 1:10:41So final question here.
- 1:10:42When I run this, what do I get back in Python?
- 1:10:45Obviously there's a nice async and synchronous Python API to talk to this.
- 1:10:50Yeah.
- 1:10:51But when I run this query in Python, what do I get?
- 1:10:54It depends on how you run it.
- 1:10:56Yeah.
- 1:10:57We offer you two modes, essentially two output modes.
- 1:11:00Any HQ query can be compiled as JSON.
- 1:11:02In our Python client, you just say query JSON.
- 1:11:05And it will return your JSON data, like ready to be pumped to your front end.
- 1:11:09Or you can just say query.
- 1:11:10And when you say query, it will return you rich Python objects.
- 1:11:14So you'll have movie Python object, which with a title, a string attribute with an actors list,
- 1:11:19which will have factors, objects within it, et cetera.
- 1:11:22It's also very compact, like on the IO level.
- 1:11:25So we are not sending like super fat tables or anything.
- 1:11:29The data is neatly serialized.
- 1:11:31So no need for any duplication.
- 1:11:33Yeah, that matters.
- 1:11:34Anything.
- 1:11:35It's just like you have your native object data model in the database.
- 1:11:39You query it and you get objects out of it.
- 1:11:43So you never have to think about like any tables or anything.
- 1:11:46It's always high level.
- 1:11:47Nice.
- 1:11:48All right.
- 1:11:48Final question.
- 1:11:49Then we really do have to wrap it up.
- 1:11:50One of the things that's really nice about ORMs is I can say my thing dot, and I get a list
- 1:11:56in my editor of what I should be getting back from the database.
- 1:11:59Can I do that with this?
- 1:12:02I know like the movie is basically defined in the GraphQL schema definition.
- 1:12:08Is there a way to do like a type shed type thing?
- 1:12:10Yeah.
- 1:12:11EdgeDB.
- 1:12:12Sorry.
- 1:12:13I don't know.
- 1:12:14Maybe it's not a DB schema language, but is there a way to do like a type shed thing to say,
- 1:12:17well, that thing you get back looks like this.
- 1:12:19Yes.
- 1:12:20Unfortunately not in Python yet.
- 1:12:22In TypeScript, we just released our query builder and it's insane because the API of the
- 1:12:27query builder super closely replicates the layout of the SQL query.
- 1:12:34It's basically like one to one correspondence.
- 1:12:36It's like almost like same thing.
- 1:12:38And in TypeScript, we just focused on TypeScript first, then Python is next.
- 1:12:42But for TypeScript, yes, you reflect your schema with just one command line command.
- 1:12:47And in VS Code, you now have full autocomplete.
- 1:12:50You can express your queries in TypeScript no matter how nested they are, no matter what
- 1:12:53kind of computation you do.
- 1:12:55It's still the same idea.
- 1:12:56Whatever query you build in your TypeScript is going to be just single SQL query, just single
- 1:13:00SQL query.
- 1:13:01It's going to be fast.
- 1:13:02And you have full autocompletion and more.
- 1:13:05You actually have full return type inference.
- 1:13:08So you don't have to type anything.
- 1:13:09You have a query, your VS Code and TypeScript, they will know the type of the data that's going
- 1:13:15to be returned.
- 1:13:16Interesting.
- 1:13:17Okay.
- 1:13:18It works like magic.
- 1:13:19We're going to see if we can replicate this experience with Python and mypy.
- 1:13:24This is going to be our goal to make something like this happen.
- 1:13:27Right now, we just have this low level, well, relatively low level client API for Python.
- 1:13:31You can run any SQL query.
- 1:13:32You can get data for it.
- 1:13:34You can do it in async or sync.
- 1:13:36Entirely up to you.
- 1:13:37But the typing integration specifically isn't there.
- 1:13:40And second part of this question is that we are looking in future implementing a language
- 1:13:47server protocol for EdgeDB.
- 1:13:48So installs it locally and then VS Code would just connect to it.
- 1:13:52And then you would have your autocomplete for EdgeQL queries, for schema files.
- 1:13:56This is going to be great, but I'm just not sure like what kind of ETA we can put in it.
- 1:14:00Probably not for 2.0.
- 1:14:01Right.
- 1:14:02Okay.
- 1:14:03Yeah.
- 1:14:03Looking forward to it.
- 1:14:04Very neat work on EdgeDB and obviously all the building blocks that we talked about
- 1:14:07at the beginning.
- 1:14:08Congratulations.
- 1:14:09Thank you, Michael.
- 1:14:10Yeah.
- 1:14:11You bet.
- 1:14:12All right.
- 1:14:13I'll list my Pi as well.
- 1:14:14My Pi is a great thing.
- 1:14:14Use my Pi.
- 1:14:14Cool.
- 1:14:15Right on.
- 1:14:16All right.
- 1:14:17Final call to action.
- 1:14:18People are interested in any of your projects.
- 1:14:19Probably primarily EdgeDB.
- 1:14:19What do you say?
- 1:14:19How to get started?
- 1:14:20Yeah, absolutely.
- 1:14:21It's ready for you.
- 1:14:22It's a 1.0.
- 1:14:23It's a stable.
- 1:14:24Follow us on Twitter.
- 1:14:25It's Twitter edge database without any underscores or dashes.
- 1:14:25Just edge database.
- 1:14:26Follow us on Twitter.
- 1:14:26You will find the discord link right in the Twitter description.
- 1:14:26So join our discord.
- 1:14:26We try to grow community.
- 1:14:26And yeah, build something amazing.
- 1:14:27EdgeDB.
- 1:14:27I can't really do it.
- 1:14:28I can't really do it.
- 1:14:29You can't really do it.
- 1:14:30I can't really do it.
- 1:14:31I can't really do it.
- 1:14:32If you want to do it.
- 1:14:33If you want to do it, you can't really do it.
- 1:14:34And then you can't really do it.
- 1:14:35If you want to do it, you can't really do it.
- 1:14:36You can't really do it.
- 1:14:37If you want to do it.
- 1:14:38You can't really do it.
- 1:14:39So if you want to do it, you can't really do it.
- 1:14:41If you want to do it, you can't really do it.
- 1:14:42If you want to do it.
- 1:14:43If you want to do it, you can't really do it.
- 1:14:44You can't really do it.
- 1:14:45If you want to do it.
- 1:14:46Find the discord link right in the Twitter description.
- 1:14:49So join our discord.
- 1:14:51We try to grow community and yeah, build something amazing.
- 1:14:55EdgeDB.
- 1:14:56I can say it like with full confidence.
- 1:14:58EdgeDB is the most amazing things that thing that ever happened to relational databases.
- 1:15:03So take a look at it.
- 1:15:04This is the beginning of hopefully a big movement.
- 1:15:07Yeah, fantastic.
- 1:15:08Let me put in one final postscript question.
- 1:15:11Sorry.
- 1:15:12I really wanted to ask you this and I think it matters for people considering adopting it.
- 1:15:15But do keep it super quick.
- 1:15:17What's the business model?
- 1:15:18Like when you guys released this thing, is it how do people get it?
- 1:15:21Will there be a free version?
- 1:15:23What's the story?
- 1:15:24So EdgeDB is fully open source.
- 1:15:26It's Apache two licenses.
- 1:15:27It's extremely permissive.
- 1:15:28No strings attached.
- 1:15:29We'll make money by running EdgeDB for you.
- 1:15:31Essentially, we will have a hosted version of EdgeDB.
- 1:15:34EdgeDB as a service.
- 1:15:35Yeah, absolutely.
- 1:15:36And this is how most other these companies make money these days.
- 1:15:38It's not anymore about enterprise version of your database so much.
- 1:15:42It is about, hey, can you run this?
- 1:15:44It's a database for us in the private cloud.
- 1:15:46Right.
- 1:15:47This is what businesses want.
- 1:15:48Back it up, scale it.
- 1:15:49Give us all that kind of back.
- 1:15:50Exactly.
- 1:15:51Okay.
- 1:15:52We're actively working on that.
- 1:15:53Although you can run EdgeDB right now on top of Aurora Postgres, RDS Postgres, Google Cloud.
- 1:15:58We have guides for that.
- 1:15:59So if you need to deploy your HDB application, we have your back.
- 1:16:02But we will have this native, proper cloud version of HDB with which you will be able to just, with one terminal command, you will be able to bootstrap a cloud database for yourself.
- 1:16:13It's going to be amazing.
- 1:16:14All right.
- 1:16:15Fantastic.
- 1:16:15Thanks, Gary.
- 1:16:16Thank you.
- 1:16:17Yeah.
- 1:16:18Bye.
- 1:16:19Bye.
- 1:16:20Bye.
- 1:16:21Bye.
- 1:16:22Bye.
- 1:16:23Bye.
- 1:16:24to check out what they're offering. It really helps support the show. Take some stress out of
- 1:16:28your life. Get notified immediately about errors and performance issues in your web or mobile
- 1:16:33applications with Sentry. Just visit talkpython.fm/sentry and get started for free. And be sure
- 1:16:40to use the promo code talkpython, all one word. Add high performance, multi-party video calls to
- 1:16:45any app or website with SignalWire. Visit talkpython.fm/SignalWire and mention
- 1:16:51that you came from Talk Python To Me to get started and grab those free credits.
- 1:16:54Want to level up your Python? We have one of the largest catalogs of Python video courses over at
- 1:17:00Talk Python. Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:17:05And best of all, there's not a subscription in sight. Check it out for yourself at
- 1:17:09training.talkpython.fm. Be sure to subscribe to the show, open your favorite podcast app,
- 1:17:14and search for Python. We should be right at the top. You can also find the iTunes feed at
- 1:17:19/itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm.
- 1:17:26We're live streaming most of our recordings these days. If you want to be part of the show and have
- 1:17:31your comments featured on the air, be sure to subscribe to our YouTube channel at talkpython.fm
- 1:17:36slash YouTube. This is your host, Michael Kennedy. Thanks so much for listening. I really appreciate it.
- 1:17:42Now get out there and write some Python code.
- 1:17:44Bye.
- 1:17:44Bye.
- 1:17:44Bye.
- 1:17:45Bye.
- 1:17:46Bye.
- 1:17:47Bye.
- 1:17:47Bye.
- 1:17:48Bye.
- 1:17:48Bye.
- 1:17:48Bye.
- 1:17:48Bye.
- 1:17:49Thank you.