Sharding Postgres without extensions with PgDog founder, Lev Kokotov
I chat with Lev Kokotov to talk about building PgDog, an open-source sharding solution for Postgres that sits outside the database. Lev shares the journey from creating PgCat to launching PgDog through YC, the technical challenges of sharding, and why he believes scaling Postgres shouldn’t require extensions or rewrites.
Everything we said
Aaron Francis
Welcome back, my friends. I'm so glad that there are enough people that care about this stuff that I can make a podcast out of it. It's, it's a great delight for me. My name is Aaron Francis. I am your host, and today I'm talking with Lev Kokotov about sharding Postgres. We're talking about pgdog, which is not a Postgres extension. Everything's an extension, not pgdog.
You'll have to listen to find out why he went that route. This is a great, this is a great interview. He's very down to earth, very low-key. It's a lot of fun. As a slight programming note, I'm curious your take on this. Um, I'm thinking of taking on sponsors for this show to help me get it edited and produced a lot faster. Right now, I just do it all myself.
But here's the caveat: I don't wanna take on database sponsors. Here's my thinking. I wanna keep the content pure, and I don't want people to be hesitant to come on because their competitors are sponsoring, and, you know, I don't wanna, I don't wanna introduce this pay-to-play thing, where somebody sponsors and then they get to come on. I, I just don't wanna do any of that. So let me know what you think.
Who should I take on as a sponsor for this podcast, provided they're not a database company? Okay. Enough meta programming. Let's get to the show. Hey, y'all. Welcome back. Today we've got Lev Kokotov from pgdog. Not only pgdog, pgcat too. So we're gonna talk about the whole thing. But first, Lev, do you wanna introduce yourself?
Lev Kokotov
Sure. Uh, thanks for having me, Aaron. Uh, I'm Lev. I've been working on databases for a long time. Uh, been an engineer all my life. Self-taught originally, then went to school, then got a couple gigs at a few startups, then worked for Instacart. Uh, started my previous company, uh, before this, so it's my second startup. I've been coding in Rust with Postgres for quite some time.
We could talk about that, but that's the short summary about me, I think.
Aaron Francis
Perfect. Okay. So before we get started on Postgres, uh, tell me the self-taught and then went to school story, because I am self-taught, uh, in the, you know, the computer science field. I got my degree in accounting. But I never went back and got, like, a, a CS degree or even anything related. So what's your self-taught and then school story?
Lev Kokotov
Yeah, for sure. Um, when I was a kid... Well, kid, I guess I was, like, 16. I, I just was interested in computers. Um, I was playing a lot of World of Warcraft. It's okay, judge away. It was a different time.
Aaron Francis
Classic. No, no, it's okay. I was a Red Alert 2 guy for many, many years, so spiritually similar.
Lev Kokotov
Me too. Yeah, me too. I loved Red Alert 2, for sure. Uh, three as well. Um, yeah, so I just, like, started... I was on the computer already, so I just kinda started programming just a little bit for fun, just to learn what it's all about. Uh, I started with C++, which was a big mistake because-
Aaron Francis
Mm
Lev Kokotov
... I couldn't write anything. It was so hard. And I just kind of assumed that I wasn't just good at this, I wasn't good at this, so I just wouldn't bother. Uh, so I decided to study, study, uh, social science. I went into pre-law, did a little, little bit of political science for, like, about three, four years. But at the same time, I was also kinda, like, programming on the side, and I even got, like, a freelance job as a, like, a PHP programmer for a hot second, and-
Aaron Francis
Yeah. Multiple
Lev Kokotov
I mean, we all start with PHP.
Aaron Francis
Yeah. Some of us, some of us stick with it, but yes, we all start there, so we're all the same in that regard.
Lev Kokotov
Yes, we are. Um, you know, it took me like five years to realize, like, you know, like I'm... Most of the time I'm just, like, coding. I'm enjoying this. Should probably, like, do this for real. And then-
Aaron Francis
Mm-hmm
Lev Kokotov
... I was like, "Well, you know, computer science degree sounds really good. Uh, you know, I'll just try it." And it was honestly the hardest thing I've ever studied. I, like, it took me, like, three years to finish and, uh, it was, it was actually really tough. But yeah, it was worth it, honestly. Like, I learned a lot of, like, the theory. I just learned to, like, you know, like, bang my head against the problem, like, for, for a semester, frankly.
Aaron Francis
Mm-hmm.
Lev Kokotov
And then kind of... You, you kind of learn about this about yourself, that you can actually solve all these problems that you thought were super hard, and I think that's the best lesson that I got out of it. Yeah.
Aaron Francis
So y- uh, that was gonna be my question, is was it worth it? And it sounds like it definitely was. And from your perspective, obviously you learned fundamentals, but you think the s- learning the stick-to-it-iveness is, is the most valuable thing you learned there?
Lev Kokotov
Yeah. They, they... I think, I think that's the case, yeah. They kind of put you on a timeline, and they give you this, like, playbook, and they tell you what to learn, and it kind of teaches you a little bit of discipline around programming, 'cause it's sometimes hard to kinda, like, stick with something and be like-
Aaron Francis
Mm-hmm
Lev Kokotov
... especially if you're, like, just doing it for fun on the side. Like, you just, like... It, it took me, like, maybe like six or eight years to learn Rust as a language, just because I just was doing it on the side, but I didn't really care.
Aaron Francis
Yeah.
Lev Kokotov
Uh, and I just kinda gave up multiple times. But in school, you know, I had three months. If I didn't learn something, I would fail the class-
Aaron Francis
Mm-hmm
Lev Kokotov
... and that, that would suck, so.
Aaron Francis
Yeah.
Lev Kokotov
Yeah.
Aaron Francis
Oh, man. So interesting. Okay, that's not what we're here to talk about, but that is-
Lev Kokotov
Okay
Aaron Francis
... terribly interesting. So what we're here to talk about is Postgres. So I did an episode recently with, uh, Sugu, uh, who is building Multigress, and many people were like, "Hey, we should talk about pgdog." And I was like, "Let's talk about pgdog." So pgdog exists. Uh, pgcat also exists.
So let's start with, let's start with pgcat. Tell me what that is and a little bit of the history before we move into your, your current one, which is pgdog.
Lev Kokotov
Yeah, for sure. Um, I wrote pgcat between jobs. Uh, I was, uh, like a database engineer at Instacart for four years, and we ran into all kinds of, you know, scaling problems with Postgres, including sharding. Um, and we did a lot of those, a lot of that stuff manually, just ad hoc, you know, with Bash scripts, honestly, and just, like, hacking pgbouncer a little bit. Um, and that, that was great.
Uh, and then I was kinda, like, done and, you know, took a break and, you know, what I like to do between jobs is kind of like work on all these passion projects that I wish I had the, the chance to work at in a real job, but they don't-
Aaron Francis
Yeah
Lev Kokotov
... typically let you do that. So, uh, I had a month off between jobs and I wrote, I put my thoughts on paper, wrote pgcat in Rust, uh, 'cause again, I was still learning Rust at the time And I reached out to a couple of my friends at Instacart, and they were- and I was like: Hey, uh, I wrote this thing that we always talked about, you know, sharding for Postgres. Isn't that cool?
And their first response was like: Didn't you just quit? Like what are you doing?
Aaron Francis
Yeah. Weren't you supposed to be, like, on sabbatical for a month until you start your new job? Yeah.
Lev Kokotov
Yeah, yeah, yeah. Exactly. And they were like: Okay, fine, whatever. So they kind of picked it up, took a look at it, like fixed it mostly, 'cause, uh, you know, I didn't have access to like massive production scale anymore-
Aaron Francis
Sure
Lev Kokotov
... so they did. Uh, so they like, they ran it against all their production DBs and eventually like migrated to PgCat, uh, from pgbouncer, which was really, really fun to see. Um, so that's really the-
Aaron Francis
Oh, wow.
Lev Kokotov
Mm-hmm.
Aaron Francis
They, they, they migrated from pgbouncer to PgCat?
Lev Kokotov
Yeah, that's right. Yeah.
Aaron Francis
So give me the high level, um, give me the, the elevator pitch for what is PgCat?
Lev Kokotov
Well, PgCat is, is I would say a really advanced connection pooler and proxy. Um-
Aaron Francis
Okay
Lev Kokotov
... you know, it can do connection pooling, sure, but it can also do load balancing. So if you have multiple replicas, you can just point your app at PgCat, and it'll just take care of everything. Load balancing queries between multiple replicas, spreading the load evenly, and then even splitting writes and reads. So if you have a primary and, and multiple replicas, which, which you obviously would-
Aaron Francis
Mm-hmm
Lev Kokotov
... um, you don't have to, you know, rewrite your code in your app to like point the write queries to the primary end read queries to the replica. PgCat will take care of that as well.
Aaron Francis
Cool.
Lev Kokotov
And I think the one really cool feature about it is failover. So if one of your replicas goes offline because of a hardware failure, PgCat will automatically remove it from the load balancing pool and move traffic-
Aaron Francis
Mm
Lev Kokotov
... to whatever is left. So you get your four nines of uptime for your Postgres replicas, which was a huge issue for us at Instacart at least.
Aaron Francis
Mm-hmm.
Lev Kokotov
We would lose a replica almost every week or so because we had like hundreds of them.
Aaron Francis
So you're working, you're working in this high scale environment, and then you are gonna switch jobs, and so you have some time off work, so you decide to work, which is classic. Um, what is it about, what is it about pgbouncer that you looked at it and you're like: "Mm, no, I'm gonna just fundamentally write a brand new thing"?
And what did you do, what did you do differently to, to make that worth the effort?
Lev Kokotov
Yeah, great question. Uh, we actually forked pgbouncer at Instacart to add a little feature to it. It took me like two months to just add something really trivial, because it's written in C. I'm not, I'm not a C expert. You know, it took me a little bit to learn the language. You know, you could say it's a simple language, but underneath you really have to manage a lot of complexity yourself.
Aaron Francis
Mm-hmm.
Lev Kokotov
Memory management, you know, pointers. I seg faulted that thing so many times before I got anything to work. Uh, probably it's just on me, but frankly just, I just kind of looked at it, I'm like: Well, I don't think I can add features trivially to this. It would take me months, years, um-
Aaron Francis
Mm
Lev Kokotov
... to, to change it in a, in a way that's reliable and safe. And the connection pooling itself is like, it's not that much, that's not that hard of a problem to solve, frankly. Uh, you can write a connection pool yourself, like, you know, give yourself a month maybe, and you, you, you'll probably be able to do it. Uh, and I was like: Well, I'll just write it in a language that I know really well and I can build on later. Like the-
Aaron Francis
Mm-hmm
Lev Kokotov
... the more interesting features are not really connection pooling, it's everything else that I would like to add to it. So I just rewrote the connection pooler. It took me like, you know, a couple weeks. Uh, and then I just started adding more stuff to it. So that's, that's probably the reason why.
Aaron Francis
So I have to imagine that some of this was, uh, some of this was a scratch your own itch exercise. So it wasn't, it wasn't a purely rational exercise, but some part of it is like: Hey, I want this thing to exist in a way that is easy for me to extend, modify, control, tweak, change, and unfortunately pgbouncer is, is not that thing.
And so the combination of those two reasons led you to just take this time to, to write your, your own little project, which sounds like has become a very big project. So what is the status of PgCat today?
Lev Kokotov
Um, well, so unfortunately, like we don't maintain it anymore. Uh, I moved everything to PGDog. Um, and the reason for that was, uh, the architecture for PgCat was kinda like... It was like a V0 or a V1 of what I really, really wanted to build.
Aaron Francis
Mm-hmm.
Lev Kokotov
I wanted to add support for cross-site queries, automatic shard detection, uh, just like making a true like horizontally scalable almost database engine that's powered by Postgres-
Aaron Francis
Mm-hmm
Lev Kokotov
... behind the scenes. Um, and PgCat was like you would have to rewrite mid- the majority of it. Um, so I decided to start a new project. Uh, plus, uh, PgCat was kind of ish sponsored-ish by my last company, which unfortunately shut down as well, so-
Aaron Francis
Mm
Lev Kokotov
... I just decided to start something new. Uh, people still use it in production. People still ask me questions about it. I, you know, happily tell them like what's going on. It's, it's reasonably stable. It's used in prod-
Aaron Francis
Mm-hmm
Lev Kokotov
... so people can just pick it up and, and, and use it. That's completely fine. Uh, but I don't think any of the original folks are still working on it anymore.
Aaron Francis
Is there a lead maintainer or community around it, or has all that energy moved over to, to PGDog now?
Lev Kokotov
Um, partly yes, partly no. Um, uh, so there's two guys who helped me build it, uh, one at Whatsignal, Whatsignal the company, and one at Instacart. Uh, Mostafa, you probably, probably heard of him. He did a bunch of talks on, on how, how they do rails over there, which is incredible. Um, they just kind of solved the problem that, that, that they were looking to solve with it. Uh-
Aaron Francis
Cool
Lev Kokotov
... and it's stable. It's running in prod. They don't need to make any changes to it anymore, as far as I know. So there's no real reason for them to add more stuff. Uh, so I think that's kind of the state of it at the moment. And-
Aaron Francis
Y'all, y'all heard it here first. Completed software. The first time, the first time in history they set out to solve a problem, and they solved it, and they decided we don't need to add a bunch of useless stuff to it.
Lev Kokotov
Well-
Aaron Francis
So
Lev Kokotov
... yeah. I mean, useless perhaps to them in particular. I think there's a lot of-
Aaron Francis
Exactly
Lev Kokotov
... things you could, you can add, but yes, you can choose to stop and just kind of-
Aaron Francis
Yes, you can-
Lev Kokotov
Yeah
Aaron Francis
... which is crazy. So, uh-
Lev Kokotov
Yeah
Aaron Francis
... for them, they solved the problem, and you looked at it and you said, "I want to do more. This needs to be more powerful, and maybe ... solve a different problem, which sounds like the reason that the, the dog and cat kind of split is, "Hey, this works really well for what it does. In fact, I want it to do something kind of different." So talk me through, um, 'cause pgdog is, uh, just recently through YC.
Is that correct?
Lev Kokotov
That's correct, yeah.
Aaron Francis
Just like this year. Okay.
Lev Kokotov
Yeah.
Aaron Francis
So pgdog is a company that you started, has gone through YC, and plays in the same space. So talk to me about, um, deciding, "I wanna do another one. It's gonna be another animal. It's gonna be similar, and we're gonna take it through YC." Before we get into the technical stuff, talk to me about that journey coming out of cat to dog.
Lev Kokotov
Yeah. That's a, that's a great one. So this time I didn't take a month. Uh, this time I took about six months between, between, between gigs. So my last company, you know, uh, shut down and I was just like, "Well, you know what? I'm just gonna do nothing for, for a little-
Aaron Francis
Mm
Lev Kokotov
... for a little while." Um, I lasted exact- exactly two weeks before I started-
Aaron Francis
Yeah, I was gonna say. Yeah.
Lev Kokotov
I started, started coding like a maniac. And some of the projects that I built in between, I would... don't wanna talk about 'cause they're really dumb, and I just, I kinda did it on purpose just, like, to code some random things. Like, I coded an app to, to track my dog's, uh, you know, behaviors and stuff. I just wanted to learn-
Aaron Francis
Mm-hmm
Lev Kokotov
... like a, like a front-end language or whatever, like a mobile app, whatever. Uh, I learned how to use Supabase and all that stuff. Uh, and then towards, like, month four or so, I was like, "Well, listen, I should probably get back to, like, reality and code something that I actually like and enjoy and I wanna do." And I was like, "Well, I have this unfinished thing. Like, I started this, I didn't finish it.
Let's try again. Like, third time or fourth time by now is the charm. Let's do it." So I spent again a few weeks c- writing code, just getting it done, and I wrote a POC, and I'm kind of sitting there and I'm like, "I should probably get a job," right? 'Cause, like, I have to pay the bills, you know. It's, it's, this is great, but let's, let's maybe get a job and move on. Um, so I applied to a few jobs, got a couple offers, but then it was just like, I can't.
I don't think I... I don't wanna, I don't wanna do, like, the, the, that kind of stuff anymore. So, you know, I took a shot in the dark, applied to YC. You know, my chances are one in, like, 20,000. You know, it's better than zero. Uh, to, to my surprise, uh, I got a call from Gary Tan who said like, "Yeah, you, you can join." And that moment, yeah, uh, I'll never forget that day.
Uh, I missed his call, of course, 'cause I was-
Aaron Francis
Mm.
Lev Kokotov
I was, I was, I was gaming. I was playing a game. I was... My phone was on silent and then-
Aaron Francis
Mm-hmm.
Lev Kokotov
You know, you know the, um... I have a, I have an Android phone. We could talk about that, too. Uh- But it transcribes your, your voicemail and it says like, "Hey, this is Gary Tan from Y Combinator. Please call me back." And I'm like, "That's not a call I should have missed."
Aaron Francis
Mm-hmm.
Lev Kokotov
Um.
Aaron Francis
Yeah, just tell him you were working hard on the product when he called. Um-
Lev Kokotov
Super.
Aaron Francis
So did you-
Lev Kokotov
No
Aaron Francis
... did you apply as a, a solo founder? Because I know that, um, or at least the lore is they prefer, they prefer co-founders. So you applied as a solo founder with a technical product, and did you have any sort of product market fit, revenue, anything at that point?
Lev Kokotov
No. No product market fit. Well, I guess you could say, like, I built something similar before and it's used in production-
Aaron Francis
Okay
Lev Kokotov
... at, at a couple big companies, so y- that, that's a good signal, I think.
Aaron Francis
Mm-hmm.
Lev Kokotov
So that was my big, like, that was a huge part of my application. Like, "Hey, like, I built something like this before. It's used in prod. I think this is cool. The market for Postgres is huge." Like, I've been working at, on Postgres for, like, eight, nine years. Who knows?
Aaron Francis
Mm-hmm.
Lev Kokotov
Been forever. So I think that helped a lot. I think they, they kind of looked at that and kind of overlooked the, the no co-founder part.
Aaron Francis
Mm-hmm.
Lev Kokotov
Uh, so, uh, there's, like, a few other solo founders in my batch, so I, I don't know if they prefer solo, uh, like, to have, for you to have a co-founder or it's just people want to have a co-founder and they apply together.
Aaron Francis
Mm-hmm.
Lev Kokotov
I just kind of... It's kind of a self-reinforcing function probably. But no, I never felt like I was, you know, you know, that different, I guess.
Aaron Francis
Hmm. So what was your pitch to them? Um, like, I get it from the technical side. Like, from the technical side, I've done this thing before. I've got these ideas of how it can be, you know, more powerful, more useful, more helpful. What is your pitch going into Y Combinator of why this is going to be, you know, a billion-dollar company?
Lev Kokotov
Yeah, no, that's a great question. Um, well, a lot of people run Postgres these days. Uh-
Aaron Francis
Mm-hmm
Lev Kokotov
... the stats are kinda getting a little bit crazy, but, you know, last year fif- based on my research at least, like, 50% of all new databases that are created in the world, and that includes Dynamo, you know, MongoDB, things that have nothing to do with SQL. Like, 50% of those databases is Postgres. Uh-
Aaron Francis
That's crazy.
Lev Kokotov
So, like, this database is growing like crazy. Uh, it's gonna beat Oracle, it's gonna beat MySQL, it's gonna beat all these guys. Um, but it doesn't have, like, a reasonable scaling product. Like, there's no sharding solution for Postgres out there. There is for MySQL, there is for Dynamo obviously, there is for Cassandra, Scylla, Mongo. All that is sharded. Postgres is not.
And people have tried this many, many times. Well, I shouldn't say many, many times. They've tried it a couple times.
Aaron Francis
Mm-hmm.
Lev Kokotov
Uh, one of them was very successful, uh, Citus. Uh, they, it, it took them eight years to build something amazing. Uh, they eventually got sold to Microsoft, which is great. Uh, but then it kind of, you know, died. Uh, not-
Aaron Francis
Mm-hmm
Lev Kokotov
... not, not died, but kind of the development stopped and people don't really use Citus as much as we'd like. So I just saw this, like, gap. I wanted to build something like this for myself personally, 'cause I'm a Postgres user. I want this to exist for Postgres. Uh, and I've seen it really, really needed at Instacart, and I believe that there's easily 1,000 companies out there who would need that kind of product as well.
Aaron Francis
Cool. So you, you relied on previous experience and, uh, obviously growing market, and there's at least one in this exact space that got, that exited to Microsoft. So you had some sort of directionally correct bet that this, this could be a thing.
Lev Kokotov
Yeah.
Aaron Francis
That makes sense. That makes sense to me. So then let's talk about the Um, let's talk about the technical details of pgdog. So let's, uh, let's start with a high level. We'll do another elevator pitch. High level, what is pgdog, and what are the areas of scaling that it concerns itself with?
Lev Kokotov
Yeah. Great question. So if you want to associate one thing with pgdog, it's gonna be sharding Postgres-
Aaron Francis
Yeah
Lev Kokotov
... and doing it in a way that is effectively transparent to the application. Uh-
Aaron Francis
Okay
Lev Kokotov
... my pitch is, like, you don't have to change Postgres or you don't have to change your app to make it work, which I think is kind of cool. Um-
Aaron Francis
It's compelling.
Lev Kokotov
Will it work? I, I believe so. I think we're gonna run into a ton of edge cases around, like, complicated cross-check queries, aggregates, uh, window functions, and CTEs-
Aaron Francis
Really
Lev Kokotov
... and foreign keys, unique indices. I-
Aaron Francis
Mm-hmm
Lev Kokotov
... I have a list. I have a roadmap that you should look through-
Aaron Francis
Yes. Yes
Lev Kokotov
... and-
Aaron Francis
All, all of those things. Yes.
Lev Kokotov
And most of them are like to-do, to-do, to-do.
Aaron Francis
Mm-hmm.
Lev Kokotov
Uh, some of them are kind of working, some of them are not yet. Uh, but th- this is what it's gonna be. Uh, it's gonna be really fast, transparent, sharded Postgres. Uh, and the data layer is gonna be all entirely just, like, community PG. Like, not... No forks, just, just Postgres, and everything that makes it scalable is manipulated at the network layer, so one, one hop above, uh-
Aaron Francis
Mm
Lev Kokotov
... inside pgdog. Um, so we make that completely transparent. Um, that would be it.
Aaron Francis
Okay. And it... And, um, compare at a, at a, at a high level, compare, um, pgdog to Citus. So we know Citus got acquired, they went into the Borg, and maybe have slowed down, stopped, you know, pushing. Um, architecturally or fundamentally, do they concern themselves with the same things, Citus and pgdog, and is there any fundamental architecture difference that you looked at Citus and said, "I don't wanna do that," or did you look at Citus
and say, "I definitely wanna do that on any of them"?
Lev Kokotov
Yeah. So great question. So, uh, I, I wanna say there's two architectural differences, and I remember one very, very clearly. And by the time I finish the sentence, I will probably remember the second one. So let's start with the first one that I really, really remember well.
Aaron Francis
Let's do.
Lev Kokotov
Let's do, yeah. Um, Citus runs inside Postgres. Uh, it's an extension.
Aaron Francis
Mm-hmm.
Lev Kokotov
Uh, so to deploy it to prod, you need to use one of your PG instances as the coordinator, and you could only really have one. Um, and that creates a certain limitation of throughput. Uh, you have to push everything through PG. It's process-based, which is usually fine, but once you start throwing, like, millions of queries at it, uh, you can't, like, horizontally scale your actual sharding layer.
Aaron Francis
Mm.
Lev Kokotov
Um, pgdog is an application that runs entirely outside of Postgres. Uh, we took the SQL parser from PG, like the actual C code from PG, and copy it into pgdog, so we have-
Aaron Francis
Cool
Lev Kokotov
... 100% query compatibility, but we don't have the query engine, so we have to rebuild some of those, uh, rebuild some of those features. But what this allows us to do is we can have, you know, end pgdogs running together in a pack and- ... and, and shard your Postgres in parallel. So it's completely... It's, it's much more scalable, and the latency profile for pgdog is, is considerably, considerably lower.
So it's, like, uh, to run a query through Citus, you'll notice the latency, and if you run it through pgdog, the latency would be much, much, much, much, much smaller, which makes it actually feasible for, like, OLTP use cases, which I'm targeting. Um-
Aaron Francis
Mm
Lev Kokotov
... Citus was more OLAP, like online ware- data warehousing, if you will. So analytical queries and, you know, they spent years and years and years building the analytical engine, uh, which pgdog is quite a bit behind. Uh, so they support a lot of really cool, like, powerful aggregates which pgdog does not yet. But when it comes to online use cases, you know, transactional read-write data, uh, pgdog is considerably faster and, and that's really important because, like, at Instacart we actually considered using Citus, uh, and we couldn't because it was, it
wasn't scalable, which is a little bit-
Aaron Francis
Mm
Lev Kokotov
... a little bit ironic, but, but, but that's-
Aaron Francis
Yeah
Lev Kokotov
... that's just how it is. Um, and the second one, and I think I'm starting to remember it now, um, it was around application design because Citus kind of requires you to build your app around Citus primitives, while pgdog kind of hooks into your existing schema and tries to make it work, tries to shard an existing schema. Um, that's gonna be quite challenging, uh, but that's the, that's really the goal.
Because, uh, when you come to somebody and who wants to shard Postgres at scale, you can't ask them to rewrite their app.
Aaron Francis
No.
Lev Kokotov
Like, they have millions of lines of code. Uh, they have thousands and thousands and thousands of queries, and you have to be able to come in and, and be like, "I'm gonna shard your app and your database. I don't expect you to move your app and your data to my database." It's, it's a really big ask. Um, so that, that's, that's the path I'm taking. So tho- those are two-
Aaron Francis
So-
Lev Kokotov
... differences. Yeah
Aaron Francis
Yeah. So, uh, to, to the first one, I saw that one of your, I don't know if it was the tagline or the footer or whatever on, on pgdog's site was something like scaling Postgres without extensions. And so that is a, like, a core belief of yours is that pgdog will sit in front of Postgres, not be a part of Postgres.
And is that fully informed by, um, your time trying to scale Citus and running into those bottlenecks at Instacart, or was there some other critical insight that you said, "I don't want this inside of Postgres"?
Lev Kokotov
That's right. Uh, well, frankly both. Uh, I built an entire company before this, uh, that was based on an extension inside Postgres. Uh, PostgresML-
Aaron Francis
Mm
Lev Kokotov
... was my last, my last startup, and we tried to put machine learning inside Postgres as an extension. And working inside Postgres was, uh, like exceptionally interesting and really, really fun, but the way to deploy changes to your database through extensions is exceedingly difficult. Uh-
Aaron Francis
Mm
Lev Kokotov
... and if you put an extension that will actually do something for you Uh, you won't be able to deploy it to, like, 99% of databases out there that run on RDS or Azure or GCP that don't have your extension. So you're, you have a massive distribution problem. Meanwhile, if you have an app that you could... A network app that you deploy in front of the DB and, and it does something useful, that's trivial. You can deploy it on EC2, on ECS, on Kubernetes, whatever, and it's completely transparent.
So the distribution problem, uh, is effectively solved. So that is why I don't want to build an extension. It's just exceptionally difficult to actually give it to people and make them use it. Uh, and of course, there's the... Like, we tried it at Instacarb. We benchmarked it. We've never used it in production because, well, it didn't pass our benchmark suite.
Aaron Francis
Mm.
Lev Kokotov
It was just not fast enough. So that's, that, that's really the core of it.
Aaron Francis
The distribution thing makes a ton of sense to me, because anytime you're looking at a provider, you're looking at what extensions do they support, right? And so if you want to, if you want to get in with one of the big dogs and they don't support your, your new little extension, you're kind of hosed, right?
Lev Kokotov
Yeah.
Aaron Francis
So do you have... This is kind of outside of Pgtog- PGDog specifically, but maybe for the, just the general audience, do you have, um, like a, like a heuristic or a matrix of decisions of when an extension makes really good sense and when an extension like PGDog does not make sense?
So one of Postgres's, um, I think one of their, one of, one of their great, um, like, reasons to use it is there's an extension for everything. It's like, "Hey, we'll just put everything inside of Postgres," which can be wonderful, but obviously has some drawbacks. So do you have a heuristic of this is a good extension case and this is a good standalone app case?
Lev Kokotov
I think, I think I do. I kind of made it up in my mind, and let me know if it makes sense. Like, try a use case that they implement inside an extension and then multiply it by 1,000 and see if it continues to work. Like, for example, uh, adding a new data type, like pgvector added a new data type inside Postgres.
Aaron Francis
Mm-hmm.
Lev Kokotov
Can you have 1,000 of these columns somewhere? Absolutely. Can you have 1,000 of these indices in your database? Absolutely. It's completely scalable. Individual indices, you know, is a different story, but, but it works. It definitely should be an extension. This shouldn't be done outside the DB. Uh, another extension which I personally really like, but I don't think I'll be able to use, is pg_cron. It runs the cron jobs-
Aaron Francis
Mm-hmm
Lev Kokotov
... inside Postgres.
Aaron Francis
Mm-hmm.
Lev Kokotov
That, like, multiplied by 1,000, it's kind of hard to, to reason about. You know, you have like 1,000 of these cron jobs. They all run SQL. Like, it's all somewhere in the background. Like, it's really hard to manage. Uh, and most cron jobs, they have nothing to do with the database. They just, they want to send an email. Like, how can you do that from inside-
Aaron Francis
Right
Lev Kokotov
... Postgres, you know?
Aaron Francis
Yeah.
Lev Kokotov
Um, so that makes less of a sense to me, and then you kind of have to have another cron job anyway, so might as well just use that instead of having one inside PG. So that's my heuristic. You know, multiply it by 1,000, see if it still makes sense, and then you'll immediately kind of have a, like a gut feeling about it. Um-
Aaron Francis
Hey, that's a, that's a pretty... I don't know if you came up with that on the spot, but that's a pretty good rubric. It's one line, multiply it by 1,000. Does it still make sense? That's pretty good. Good job.
Lev Kokotov
Thanks.
Aaron Francis
Um, okay, so let's talk technically about PGDog.
Lev Kokotov
Mm-hmm.
Aaron Francis
Um, so we understand now that it is not an extension. It is a standalone thing, um, that sits in front of presumably many instances of Postgres. Um, it concerns itself with sharding and connection pooling at the very least, probably more. Um, and you pulled the, uh, query parser from Postgres proper, but not the query engine.
And so, um, I guess talk to me about, um, talk to me about the, like the architecture. I- Is it built in Rust as well? Okay, so this is, this is a, a Rust application that sits in front, and does it pretend to be Postgres to the outside world?
Lev Kokotov
That's right. That's exactly right.
Aaron Francis
Okay.
Lev Kokotov
It's, it, we implemented the whole protocol, uh, you know, from scratch. Uh, if you look at the spec, the protocol is actually not that complicated. Well, you know, you'll-
Aaron Francis
Yeah.
Lev Kokotov
Yeah.
Aaron Francis
To you, maybe.
Lev Kokotov
Perhaps. Yeah, I don't know. It took me a few weeks and I still, like, find myself making mistakes, so actually fair enough. Uh-
Aaron Francis
It's pretty complicated then, yeah.
Lev Kokotov
It, it's, yeah, it's up there. It's not HTTP, it's definitely a little bit more complex. Well, maybe. It's stateful, that's the real issue. It's-
Aaron Francis
Mm-hmm
Lev Kokotov
... you have to keep track of what the cl- each client does and what each server does. And if you-
Aaron Francis
Interesting
Lev Kokotov
... if you miss, yeah, if you miss a step, you're gonna have like a really confusing error. Uh, so Postgres is really good at detecting those errors and telling you you did something wrong, but y- you as the pooler, you have to be able to do the same thing. Um, so, you know, we keep track of transactions, we keep track of client server state, uh-
Aaron Francis
Mm-hmm
Lev Kokotov
... we keep track of prepared statements. We keep track of, you know, sharding keys, uh, replicas, primaries, where's everything at any given point, uh, memory usage, like the whole thing. So you could almost look at it as like this is, this is... It, it's not a database. Like we... Let's not, let's not get carried away. Uh, the storage part is completely manageable with Postgres, but-
Aaron Francis
Mm-hmm
Lev Kokotov
... a lot of things will, will get pretty interesting for sure.
Aaron Francis
So it is, uh, it is half of a database. It is all of, all of the front half and none of the storage. And then you-
Lev Kokotov
Yep.
Aaron Francis
So presumably the application connects, um, and at that point, uh, PGDog has the connection.
Lev Kokotov
Yep.
Aaron Francis
And then it is responsible for mapping those queries to the different shards, right? And so it goes off and queries one or N many shards, and then, um, does it... How far, I suppose, I know you still have a lot of to-dos on the list, how far are you down the path of it queries three shards to get all the data, brings it back to PGDog, puts it together into a result set, and then sends it back to the
end user?
Lev Kokotov
That's a great question. I keep estimating that percentage in my mind, and every time I talk to somebody, that percentage gets a little smaller.
Aaron Francis
Hmm. We're moving the wrong way, aren't we?
Lev Kokotov
No, uh, we're not. We're, we're learning, we're learning things, and that's really great. Uh, I knew getting, getting into this that this is a multi-year project. This could easily-
Aaron Francis
Is it?
Lev Kokotov
... be a 10-year project, 15-year project before i-i-it's finished. Uh, and that's, and that's expected, and that's really... Personally, I like that because it gives me-
Aaron Francis
Mm-hmm
Lev Kokotov
... a job for the next 15 years, and that's, like, it'll be amazing. Um, to give you a, a more simple answer, uh, if you have the sharding key in your query, like if you know which shard effectively you're gonna have to go to, it works 100%. Like, that's it. Direct-to-shard queries work today, no problem. Uh, if you don't have the sharding key, we can do the following things.
We can collect results from multiple shards and present them as one.
Aaron Francis
Mm-hmm.
Lev Kokotov
Uh, if you have a sorting, if you have sort, if you sort your results, we can also perform the sorting operation. Because as you can imagine, you, you're talking to multiple databases. Even if you send the query everywhere and ask the Postgres to sort, like the overall sorting order will be wrong.
Aaron Francis
You still have to collate them.
Lev Kokotov
Exactly. You have to collate them and then resort them as well, uh, because, you know, you have different values on different shards. You basically have to do a merge sort in the pooler and then send it over. Uh, so that's supported for at least three or four or five data types. I actually need to map every single Postgres data type. It parses it in- inside pgdog and makes sure that I have the sorting operation supported for it. And that's actually not, not as hard as, as you would think.
You just need to like kind of go through like the 50 or so data types and parse them, and then most of them are pretty, pretty easy to parse. Uh-
Aaron Francis
Mm-hmm
Lev Kokotov
... you just, you just have to do it. Um, and then aggregates are on the way. You could do min, max, sum, and count, which are, uh, I always forget the word. Transmutable? Da, da, da. Like if, you can have, you can ask for each shard to get, to get that value, and then you can combine that value in pgdog without recalculating the total result from, from the, from the raw results-
Aaron Francis
Yes
Lev Kokotov
... uh, from the raw rows. So you can combine those. But for example, average is not supported right now because for averages-
Aaron Francis
Mm-hmm
Lev Kokotov
... you have to, you have to get the total and then the average and then recombine it. Uh, so I need to write that query rewrite engine to, to, to do that. Uh, that's gonna be probably done this summer hopefully. Uh, but I also have more work to do that's a little bit different, uh, like around resharding and moving data between databases because that's really the, the, the, the really important part.
So to give you a fixed percentage, I want to say 30% maybe.
Aaron Francis
Okay.
Lev Kokotov
You know, like-
Aaron Francis
Let's say 30.
Lev Kokotov
Ah. So the people I'm talking to right now, like, uh, you know, companies that I like to do, you know, business with, uh, they're, they kind of understand what I'm doing and they want direct-to-shard queries. Like they don't want, they don't want their apps to actually do cross-shard queries because-
Aaron Francis
Right
Lev Kokotov
... uh, they're expensive and they're tricky. Uh, so for them, they're gonna target like, you know, 95% will be direct-to-shard with a sharding key, and then the 5% is where the real work will start. Uh, and that's, that's what I'm working on right now. Um-
Aaron Francis
So that is the query, that's the query serving part. Talk to me about how the... I guess backing up a step, um, we've got, we've got a massive Postgres database. We're in trouble. We call Lev. He says, "Great, let's get some pgdog in there." What, what happens then?
Because, you know, to the, to the application it should be, and is, transparent. You just connect to pgdog and do your thing, and presumably you're doing, you know, where team ID equals one or company ID equals one or whatever, and you're going to a single shard behind the scenes. But how do we get from big struggling Postgres instance to pgdog is sitting in front of multiple instances?
What's the journey there?
Lev Kokotov
Great question. Um, I'm designing two or three algorithms, or I should say like processes to do that. Uh, two of them we've done at Instacart, so they're pretty much battle-tested, and I'm gonna put that in inside pgdog's open source core. Uh, so what will happen is you'll deploy pgdog, it'll see that you only have one shard, and you'll ask it to like, "Hey, make this into three shards." And it's gonna create three separate databases.
It's gonna migrate the data, reshard the data online into these three or six or 12 shards, whatever, whatever you choose. And it is gonna do that, uh, atomically, because we're going to use, uh, logical replication, which is, you, you're probably familiar with it, but it's a way to stream application data from inside Post- like table data from inside Postgres to another instance.
Um, and we can hook into that replication stream, like actually parse the data and split it between, uh, between multiple shards. So I know. It, it, it's really cool. Um-
Aaron Francis
It is cool.
Lev Kokotov
The protocol is documented.
Aaron Francis
We're extreme nerds because that sounds very cool to me. But yeah, keep going.
Lev Kokotov
Yeah. It's, it's an actual stream. Uh, it's documented. The protocol is documented. You can see what, what's the data inside that stream, so you can read it and split it. Um, and the cool part, uh, about it, actually the cooler part I should say about it is I think Postgres 16 or 17 allows you to create, uh, logical replication streams from actual replicas, from streaming replicas in Postgres.
So I can imagine, you know, coming into this really overloaded, sad database, creating like 16 replicas in RDS, which is basically like a zero-cost operation, uh, spinning them up and stream 16, 16 tables in parallel, which-
Aaron Francis
Oh, interesting. So you have, you have the, you have the big guy. I was gonna say big dog, but dog is a technical term in this episode. You, you, you've got the big guy, the big overloaded Postgres database. You can go into RDS and say, "Give me 16 replicas," and it'll do that.
Lev Kokotov
Yeah.
Aaron Francis
Quick and easy. Been done 100 million times before. From those 16 replicas, you can get 16 different streams coming out such that your, uh, your sharding operation, if you want to call it that, is 16 times faster and not stressing out this already overstressed database.
Lev Kokotov
Exactly.
Aaron Francis
Ah, cool.
Lev Kokotov
Like, uh, let me give you an example. Like we, we didn't do that exact thing at Instacart. We snapshotted the primary, restored it separately- ... synced it up with logical replication, and then streamed from that, uh, using one, like, one table at a time. Um, one stream at a time, I should say. And that took us about a week or two to create, like a, like a sharded cluster. And it was all manual, and you make one mistake, you have to go all the way to the beginning.
Like, go back to, go, go back to, like, zero. Whatever the Monopoly, you know... Yeah, skip Go, do not collect-
Aaron Francis
Yeah. Do not pass go. Straight to jail. Yeah.
Lev Kokotov
Straight to database jail, exactly. Oh, man.
Aaron Francis
Seriously.
Lev Kokotov
How many times I dropped the replication slot and lost all my progress? It was, it was... Yeah, anyway. That's why I'm building this company and this product, 'cause I don't want anyone else-
Aaron Francis
No
Lev Kokotov
... to ever do this again. Uh, so yeah, it took us, like, two weeks to create, like a, it was like a 12 terabyte database, and we sharded it into, like, six, you know, two terabyte databases. Uh, with parallel streaming, you could do this in less than a day, probably less than a few hours, frankly. Uh, I think it would be... This will make it actually operational. It's not gonna be like a long, scary process.
It's gonna be like a quick, quick, quick thing you can get, like, real time feedback on.
Aaron Francis
Very cool. And so you said there were, you said there were a couple of ways you were thinking about this. Um, does this way, does this way have a name, and what are some of the other ways you're thinking of?
Lev Kokotov
I don't think this way has a name. I should start naming these things, 'cause it would be cool.
Aaron Francis
You should start naming it, yeah.
Lev Kokotov
Yeah. I don't know. We could come up with a name, um, in a minute. But another one is that the one we actually did at Instacart, it's actually documented in a blog post somewhere. Uh, you know, we take the primary, we create a, a backup in RDS.
Aaron Francis
Mm-hmm.
Lev Kokotov
Uh, well, actually, let me back up. We create a replication slot, I know, pun intended. We create a replication slot, create a backup, restore the backup, uh, resynchronize the backup with logical replication by moving the origin inside the replication slot. Very scary stuff. People tell us, "You're gonna blow up your database." We did not.
You know, we... People in the mailing list were like, "If you do this, you will corrupt your data. You will lose all your data." We were like, "Well, I believe you. Actually, I don't believe you, and also, we don't have a choice." So-
Aaron Francis
Ugh
Lev Kokotov
... we're just gonna, we're just gonna do it.
Aaron Francis
Terrifying.
Lev Kokotov
It is, but you can test all these things out. Like, we did all of this offline with, like, staging databases. We validated that this actually works, and then we had a rollback plan and everything. Like, we're, we're, we're not cowboys. We're not crazy. We're just... We, we like to experiment, you know? That's, that's how you-
Aaron Francis
Mm-hmm
Lev Kokotov
... that's how you push the edge, you know? Uh, the envelope or whatever the expression is. Um, so that was the way to do it, and then once you have that s- little standby running, you can actually copy data, uh, using... We did use four data wrappers and four, uh, table partitions to, like, push that data out to the actual shards with literally, like, a copy statement. Uh, it was, it was wild, but it worked.
And then at the end, we actually, we took the, uh, the hash partition logic from Instacart, it was like the C code, and we ported it into, into Ruby, 'cause our app was in Ruby, and that's, that was the routing layer. And then for the 1% of queries that could not be sharded, didn't have a sharding key, we used four data wrappers and, like, six different coordinators that you could, like, talk to and, and get these, like, uh, aggregates basically to work.
And Postgres 4 data wrappers are, like, okay, but they're not, like, they don't work at, at scale, I would say. Their, like, latency is too high.
Aaron Francis
Mm-hmm.
Lev Kokotov
But we don't have a choice. You don't have a choice. So, um-
Aaron Francis
Okay, I followed about 18% of that. So the first one sounds a lot, the first one sounds a lot more straightforward and a lot easier to get, to get your head around.
Lev Kokotov
Yes.
Aaron Francis
And so where in the, where in the, um, PG Dog handles this, you know, uh, uh, vector or s- or, uh, scale, where, where are we now for PG Dog doing this sharding part?
Lev Kokotov
Uh, like 5%, uh, not even.
Aaron Francis
Okay.
Lev Kokotov
I have to build this over the summer. Well, uh, ideally. Uh, again, it's summer. We're already in July, and I've been saying over the summer so-
Aaron Francis
I wasn't gonna tell you, but yeah.
Lev Kokotov
I mean, it's, it's, it's San Francisco. I don't, I don't know what season we are. It's always the same. Um, so anyway, I, I hope to finish it by the end of summer, 'cause at least the, the prototype should be pretty... Well, I don't wanna say straightforward again. I keep using the same word, uh, to build. But it should be, it should be very doable to have an MVP of this by the end of summer so people can start trying it out and making sure it works. Uh, there's a huge orchestration work to be done, like creating databases, synchronizing them, all of that stuff.
I don't-
Aaron Francis
Yeah.
Lev Kokotov
I don't think that should live necessarily inside the core product because we're talking about, like, making like AWS calls, and then if you're not on RDS-
Aaron Francis
Yeah
Lev Kokotov
... like, all of these things should probably be managed by some kind of cloud soft orchestr- orchestration software, which I would like to build as well. But now we're... Now I need more hands to help me with that. Uh-
Aaron Francis
Yeah. Summer's almost over, my friend. So that, I guess that was my other question is, like, if you, if you have to spin up, you know, 16, we'll s- knock it down, say four, you gotta spin up four databases, um, you as PG Dog, you don't know what provider they're on. You don't know what cloud they're on. They might just be on, you know, if they're DHH, they might be on a rack in some data center somewhere.
So, like, where do you draw the line of, of, like, this is PG Dog's responsibility and this is the user's responsibility?
Lev Kokotov
That's a good point. Um, I don't think it should really ever be the user's responsibility in the ideal world.
Aaron Francis
Mm-hmm.
Lev Kokotov
I don't think it should be inside PG Dog core necessarily. Uh, that's why I'm building... I, I wanna build a cloud basically where you can connect it to your GCP, Azure, AWS, whatever. You know, give me your key, trust me, and I'll, and I'll do this for you, right? Uh, but a lot of the logic will live in an actual, like, web app, if you will. And then PG Dog is config-driven.
Uh, you'll just update the config and say, like, "All right, this is your primary, these are your four shards that I need, I need, I need populated with data," and then you can just, like, tell it to do that, and it'll create logical replication streams. 'Cause that act- that part needs to be synchronized and high performance, so I don't want it to be, like, inside a, a weird web app.
Aaron Francis
Sure.
Lev Kokotov
Uh, so that part should definitely be in the PG Dog core. And because underneath it's all just Postgres databases, it doesn't have to be in our... Like, PG Dog doesn't need to care about where Postgres runs. It's all, you know, application layer protocol. Um, I think that that separation makes sense.
Aaron Francis
Yeah. So the clean handoff is, um, PG Dog ends up with a connection to a bunch of Postgres databases. How it got- how those databases came into existence, where they live, uh, how long they've been alive, PG Dog does not concern itself with.
If it can connect to the big guy and the four replicas, then it can do its job, which is still extremely complicated, configuring stuff, doing a bunch of stuff. But the crucial part is, can I connect to these databases that you claim exist? Is that, like, the clean separation?
Lev Kokotov
Yeah, definitely. Uh, being config-driven is really nice because you don't have to solve a lot of these crazy synchronization problems. Like, I don't need to use etcd or Consul or, like, all that, all that, all that funky stuff. Uh, I can just, like, put it in a config and then let it do its job. Um, and, and it's, it's easy to write. You can write it by hand. You can automate it, of course.
You can generate a config using some other software. So I think the separation is, is really clean and nice. Yeah.
Aaron Francis
So I'm wondering, are you building, are you, are you building a, a database cloud? Like, is... Are you building a database host, is my question. Are you building the, um, the PlanetScale for Postgres, which is, you know, complicated now. But is that what you're building? Because it sounds like you've mentioned the, the web component, but you also mentioned, um, hooking into the users or the customers'
GCP or AWS or whatever. So at, uh, uh, I guess, what is your grand vision? Is it web orchestration, or is it bring me your databases and I will take care of them?
Lev Kokotov
I think to get started, uh, it's the bring me your databases and I'll take care of them. Uh-
Aaron Francis
Okay
Lev Kokotov
... it's a really, it's a really great proposition for most companies because nobody likes to migrate to a different cloud-
Aaron Francis
Correct
Lev Kokotov
... especially a brand-new cloud. Ne- like-
Aaron Francis
Mm-hmm
Lev Kokotov
... forget, forget it. Uh, migrating to a different database, nobody wants to do that. It took us, like, a quarter to decide, a quarter, like four months, or three months is a quarter, sorry, three months to decide that we should try Aurora on one of our databases.
Aaron Francis
Mm.
Lev Kokotov
Even though they provided all the migration tools for us. And it, again, it took us months to migrate, and migration is a really, really bad word in, in the database world.
Aaron Francis
Mm-hmm.
Lev Kokotov
Uh, so I wanna start by just going to people wherever they are and sharding there. And eventually, I can see, you know, once this becomes a repeatable pattern and I- I've really, like, built PG Dog to be a great, you know, reliable, powerful software. Like, running it as part of a cloud offering would just makes, makes sense. Um-
Aaron Francis
Mm-hmm
Lev Kokotov
... now in terms of building PlanetScale for Postgres, entirely possible, I think. I think running Postgres, after all of that we just discussed, running Postgres is, sounds pretty easy. Like that-
Aaron Francis
Yeah
Lev Kokotov
... that's a solved problem. Uh, I've done this many, many times before. Uh, eventually it would probably make sense to do that, but right now, main focus is get PG Dog to actually shard Postgres, uh, at least for the foreseeable future, yeah.
Aaron Francis
So, uh, y- a couple of different times throughout this, you've, you've had good thoughts, um, on, on distribution and adoption, the whole extension thing, the nobody wants to migrate thing. Um, what is the shape of, of the company at this point? Because, uh, you went through YC as a solo founder.
Do you have multiple employees? Are you doing, like... Is it, like, con- consulting right now, or are you selling anything? Talk to me about, like, the business side of things, because you seem to be very tuned into it, especially for a technical founder.
Lev Kokotov
Yeah, no, for sure. Um, well, I just hired our first employee this week or last week.
Aaron Francis
Congratulations.
Lev Kokotov
Uh, it's crazy. Like, I meet people on the internet, and they're like, "This is really exciting and I wanna work here," and I'm like, "That's amazing. That's, that's really great." I mean, that's how it works.
Aaron Francis
That's great.
Lev Kokotov
But, you know, every time it happens, I'm just like starstruck a little bit, so.
Aaron Francis
Of course.
Lev Kokotov
He's, he's a, he's a great guy. Uh, he's already, like, pushed the, uh, code change to production. We're doing great. Uh, so the team is growing. Um, so in terms of business, I am mostly doing design partnerships at the moment. I'm looking for companies who, you know, have this need. I'm validating this is a real need and not just made up in my head. Uh, and I'm building, building the product with them.
Um, I have a few of them already online in production, so PG Dog is in production, very much so. Uh-
Aaron Francis
Okay. That's big.
Lev Kokotov
Uh, it is. Yeah. Like, I would say, like, maybe probably 80% of the code that I've written is running in production right now and being tested continuously with real traffic, which is really great. Uh, so that's really exciting, and I'm trying to deploy a few more, uh, as we speak. Uh, you know, founder-led sales. You know, I blog. I do these things. I, I talk, I, I go on podcasts. I cold email people on LinkedIn.
Uh, some of them actually answer, which is bananas.
Aaron Francis
Who, who are these people? That's crazy.
Lev Kokotov
Who are these people? Yeah. You know, directors of infrastructure, whatever, managers. Like-
Aaron Francis
Yeah
Lev Kokotov
... my, my ICP is, like, very well defined. You know, database people. Like, they'll-
Aaron Francis
Mm-hmm
Lev Kokotov
... they'll, they'll understand what's going on. Um, so that's where I'm at.
Aaron Francis
That is incredibly impressive. All this time you're talking about, "Oh, the road expands before me. There's so much. Every day, like, there's more to do," and yet you're in production places. So how did you find, um, how did you find these first people basically to, to trust you, and what was your, what was your pitch to them of, "Hey, listen, you can trust me?"
Lev Kokotov
They pitched me. Like, they just kind of find me. They're like, "PG Dog is great. We have this need. Can you deploy this?" And I'm like, "Yeah, I can deploy it, absolutely." And then we just deploy it and... Well, we test it in staging first, you know.
Aaron Francis
Sure.
Lev Kokotov
Load test it a little bit, you know. We're, we're not crazy. And then deploy to prod, spot a couple bugs I'm right there with them on a call, fix the bugs, push it to prod, iterate. You know, first design partner always, you know, has it rough. Uh, two days, we fix all the bugs, and it's in prod, right? So that's just how you do it. Uh, uh, being a YC company really helps. Uh, like my first customer is a YC company, so there's a lot of like trust-
Aaron Francis
Mm-hmm
Lev Kokotov
... that we're both kinda like, well, well-meaning people to begin with. You know, we wanna help each other, and we're not trying to like, you know, just like pack our way to something. Like we're, we're legit, you know? So that helps a lot. Uh, you know, just blog about it, talk about it, explain what you're doing. Open source most things, if not all things, you know. Don't be afraid-
Aaron Francis
Mm-hmm
Lev Kokotov
... to just like say like, "This is how it works." And sometimes people tell you you're wrong and do it this way, and I'm like, "Thank you. That's great. Now it's, now it's a core feature. Thank you very much." You know, that's just, that's how you do it. You build in the open. That's, that's the story.
Aaron Francis
So er, at some point during this you said open core. So what is the structure of the actual, of the actual code? So are you building, uh, are you building most of this in public, and so you're getting-
Lev Kokotov
Yeah
Aaron Francis
... a little community around you, and so that's a, that's a big vector by which people are finding you? And is there a proprietary, uh, sidecar, adjunct, non-core thing?
Lev Kokotov
Not right now. No, everything's open source. Like, I mean, my w- pgdog.dev, the website is closed source, but it's just a J- J- Jekyll template, like there's nothing there. Uh, the blog docs are open source, code is open source. Uh, the cloud might be closed source just because I'm embarrassed by how much bash I write, and people should not know how the sausage is made. It's just, it's not pretty, but you kinda have to, you know, do that, uh, that way.
Uh, but yeah, pgdog open source. Nothing, nothing's hidden. Yeah.
Aaron Francis
So you said this, this new person already has successfully deployed some stuff to production, which is awesome. W- congrats on, on that. Um, how, how does that deploy process work for somebody that is in prod? So presumably this person, this new employee writes some code. They're, you know, Lev has never written any bugs, but let's imagine Lev writes a bug.
The new guy fixes it. He, you know, pushes it to main. Then like, what is, what are your design partners, what does that deploy process look like to get the new version of pgdog without, or, or maybe experiencing some downtime or not? How do they get that out there?
Lev Kokotov
Yeah, great question. Uh, well, first things first, there's like a massive integration test suite that runs on main every single time, on all PRs as well. So we test everything. I think we probably are close to, you know, I don't, I don't wanna make up a number. I haven't measured this actually, but I think we're almost at 100%, uh, code coverage.
Aaron Francis
That's amazing.
Lev Kokotov
So that's all, yeah, all the benchmarks, all the, you know, all the tests and stuff.
Aaron Francis
Mm-hmm.
Lev Kokotov
Uh, and we have like a Docker container that we build on, on the main branch with every single commit, and I literally just take the sh- the sha of the Docker image, and I, I Slack, I Slack it to, to my, to my friend at the, uh, the, one of my friends and be like, "Hey, this is the sha. Deploy this." And they're like, "Great, I'll deploy it in an hour." I'm like, "Sounds great." And in an hour they come back and they're like, "Great, it's deployed." I'm like, "Success." Amazing, you know.
And then they kind of tell me-
Aaron Francis
Okay
Lev Kokotov
... what's going on. Yeah, I mean, that's just how-
Aaron Francis
Yeah
Lev Kokotov
... it works, you know. It's really simple. Like I have an, well, like an expert on the other side, there's an expert over here, and we just kind of talk on-
Aaron Francis
Yeah
Lev Kokotov
... Slack. You know, that's just it. Yeah. Um.
Aaron Francis
Okay, so this is, this is a very, you know, it's not, it's not consulting, but it's a very hands-on... You're like, you are working with the customers right now to find, uh, any, any bugs or any performance things, or to get feature requests, or to hear what's working and what's not. How vital has that been to, I guess, um, shaping the, the near term roadmap?
Lev Kokotov
It's the only way this will ever work. Uh-
Aaron Francis
Mm
Lev Kokotov
... anyone who decides to build this in an ivory tower somewhere and release it s- s- five years later once it's finished will fail. Uh, because, uh, like you can't, you can't, like you can't spend time without talking to the people who are actually gonna use it, and then kind of build something and then give it to them, and it's... Nine times out of 10, it's just not gonna work.
Not because, like your idea was wrong, but you missed like an important part of how they're actually using it. I talked to like, you know, dozens, hundreds of companies, and they all have their own little quirks about how they use Postgres and how they use poolers, how they load balance, how they want to shard. Um, so these conversations are really important. Um, and building with them is much faster-
Aaron Francis
Mm
Lev Kokotov
... because I don't have to rewrite anything that I did wrong. I just build literally what they asked me for, and I already kind of thought about, and it just confirmed to me that that's the right way to do it. Um, so that is the, like the, the Y- YC motto, just like startup motto in general is like do things that don't scale to get-
Aaron Francis
Mm-hmm
Lev Kokotov
... started. Uh, and I, and I'm gonna do things that don't scale for probably the next two, three years. I'm gonna literally sell to every single person individually. Uh, there's not gonna be a sales team here. This is gon- you're just gonna be talking to me like for the foreseeable future until we're both blue in the face and you'll be like, "Yes, I will use pgdog." Uh, s- I think that's the only way this can work.
Aaron Francis
Is it, um, like what, where does the money come from right now? Are they paying you to implement you as a company, or are they paying you to implement this thing?
Lev Kokotov
Yeah, asking for money is really important. Um, you know, design partnerships should always be paid. Uh, so I'm asking them like to pay me like a nominal sum.
Aaron Francis
Mm-hmm.
Lev Kokotov
And, and that tells me that this is valuable to people. Like if, if you do something for free, you have no signal, but if you ask for money, you have a pretty good signal that this is something that's worth your time and their time.
Aaron Francis
And how have the first design partnerships gone in terms of, like you said earlier, migrating is a scary word. Um, I imagine adding something between your application and your database is kind of scary. Way less scary, but how has that, um-
Lev Kokotov
Mm-hmm
Aaron Francis
... deploy process gone? Like the initial, um, not migration, the initial deploy, how has that gone?
Lev Kokotov
Honestly, like not as bad as you think. Um-
Aaron Francis
Not as bad as you think. I assumed it went well, but sure. Carry, carry on.
Lev Kokotov
Well, it's, it's never gonna be smooth the first time, especially with the first design partner. The first design partner-
Aaron Francis
Yeah
Lev Kokotov
... like we tested it in staging, it was fine. But then we deployed to prod and there was a couple of like, uh, I think we missed like, uh- It was something around prepared statements or something around transaction management, like the state management-
Aaron Francis
Yeah
Lev Kokotov
... that was a little bit off. Uh, it w- it didn't take anything down, it just caused, like, maybe, like, 1% of errors across, you know, across the queries, which is not great, but it's, it's not terminal. Uh, so you kind of roll it back, you fix the bug, and then you roll it forward. Um, and then as long as you have a smooth deployment pipeline for these kind of things, which, which we do, uh, you know, they're using Kubernetes, so just a push button thing.
Uh-
Aaron Francis
Mm-hmm
Lev Kokotov
... you just deploy it in, like, in less than 30 seconds, and that's it. So deploying a new code version takes no time at all. Um, so the first, the first design partner definitely takes up all the risk, but that kind of, that is great because they're telling me and they're validating that this is a real problem. Like, somebody who's willing-
Aaron Francis
Mm-hmm
Lev Kokotov
... to try something so experimental and, you know, and crazy directly in prod is telling me that what I'm working on is so important, to them at least, that they're willing to try this. Um, and then that's-
Aaron Francis
And they're willing to pay you for it. There's something that is so, so crazy and experimental, it's pushing to prod and pay you for the privilege of it. That's a pretty good sign.
Lev Kokotov
I just have to do it 1,000 more times, and then we have a company.
Aaron Francis
Yeah, exactly. Easy.
Lev Kokotov
Easy.
Aaron Francis
Straightforward at the very least. Um-
Lev Kokotov
Yeah
Aaron Francis
... uh, one, one thing you said a second ago about every, every company, you know, all 1,000 companies are doing something slightly different with Postgres, um, that made me go back to this is not an extension. Because I'm sure, you know, extensions, they all work great together, but you don't have to care what other extensions they might have, the other weird things they're doing with Postgres, because you get to sit comfortably in front of it outside of
that whole like, "Hey, did y'all change a setting on Postgres? 'Cause now PgDog's all wonky." It's like, no, no, no, totally discreet. So are you finding that to be a benefit as well? Everybody can do their crazy whatever they wanna do, and you're just kind of in the outside world?
Lev Kokotov
Yes. Uh, and that's because the Postgres, Postgres protocol, like the, the network protocol, is incredibly stable. Uh, they haven't made any, like, significant changes to it in probably, like, 20 years or so. Like, uh-
Aaron Francis
Oh, cool
Lev Kokotov
... it's, it's just like, it's well done, it's well documented, and all I'm doing is manipulating some bytes and some, and some protocol state, which is, is fixed and most likely will never change.
Aaron Francis
Mm-hmm.
Lev Kokotov
So whatever crazy stuff they do with extensions is just completely removed from what I'm doing. Yeah.
Aaron Francis
That's totally behind the curtain from you, and you super don't care about that.
Lev Kokotov
Not usually. Uh, so okay-
Aaron Francis
That's great
Lev Kokotov
... th- this is a really... Like, there's a fun article that I wrote that, uh, about sharding pgvector, which kind of, kind of goes against this thesis, where I j-
Aaron Francis
Ooh
Lev Kokotov
... where I try to, you know, care about what's inside the DB and see if I could-
Aaron Francis
Mm-hmm
Lev Kokotov
... like, change my sharding function based on the data that people are storing there, and it kind of makes sense. Uh, it's, you could check it out. It's just a little, it's a little wonky. I don't know if it actually works, but it was, it was a kind of cool prototype. Like, what happens if I, if I implement one of the, like, vector indices that I sh- uh, inside PgDog and then I shard it across multiple databases knowing that people are using pgvector underneath?
Uh-
Aaron Francis
Hmm
Lev Kokotov
... that's an extension. But that was more like a, like a prototype than, like, like was playing with the idea more than anything else. Um, I guess long story short, the general answer is no, I don't care about what they do inside Postgres. Uh, but sometimes maybe yes. Um.
Aaron Francis
Yeah. That's a, that's a good answer. There, I don't think there are any, there, there are no absolutes except the fact that there are no absolutes. So it sounds like, um, it sounds like things are picking up. You got, you've got an employee, you've got a bunch of design partners. Summer's almost over, so you're about to be done with everything. Um, so a- as we wrap up here, tell me, like, what is the next...
What, what do the next six months look like? What do you, uh, what do you want from people that may be listening? Um, and kind of tell me about cast the vision for the next six months, and then maybe after that, give me the next five years.
Lev Kokotov
Five years. In startup world, that is impossible to predict.
Aaron Francis
I know.
Lev Kokotov
Uh, in fact, uh, whatever I tell you right now will be completely irrelevant in, like, six months, I guarantee it.
Aaron Francis
Just cast a vision.
Lev Kokotov
Cast-
Aaron Francis
Just dream
Lev Kokotov
... just dream. For anyone who's listening, please come and try PgDog. It's free and open source. You can deploy it wherever you need to deploy it. Uh, I even have a Docker image. You can pull it straight from GitHub. Please try it. Let me know what I did wrong. That would be really, really helpful. Uh, if you find nothing wrong and you want to deploy this in your, in your cloud, give me a call, I would love to help. Uh, now in terms of vision, uh, sharding for Postgres can easily occupy the next five years because there's gonna be all, all kinds of crazy cross-shard, uh, cross-shard cases I need to support.
I really want to add support for, like, unique indices. That would be really cool. There's, like, so many, like, crazy optimization techniques you can, you can do there. Foreign keys across shards would be phenomenal. Like, all of these things that are, like, that would really differentiate PgDog from everybody else because nobody really does that. 'Cause these are actually difficult problems. Um, if you look at, like, CockroachDB, for example, that claims to be, like, you know, sharded PG, which is, it's not even Postgres underneath, but they don't support foreign keys across shards and, I mean, probably for a good reason, but I would still would, would wanna explore all of
these, like, niches that everybody kind of just abandoned and moved, moved over. Um, building our own cloud would be great so people can just, like, come in, you know, push a button, and deploy PgDog wherever they need to. That'd be phenomenal. That's really the scalable business part. You know, you can't have me deploy it manually in every single cloud, uh, at least-
Aaron Francis
Mm-hmm
Lev Kokotov
... not for long if we're successful. Uh, success looks like there's a push button deployment in my cloud where you get metrics, logs, you know, scaling, scaling everything, configuration, it would be phenomenal. Uh, so that's easily the next two, three years. Uh, you know, five years, I, I, I don't wanna-
Aaron Francis
I, I'll, I'll settle for two or three. You weren't gonna give me beyond six months. You gave me two to three, so I'll settle for that. That's plenty.
Lev Kokotov
Fair enough.
Aaron Francis
So this, this has been, this has been great. This has been super fun. Um, tell, tell the people where they can find you, um, on your favorite social networks, or it sounds like you're doing a lot of writing, um, about some of the, the gnarly Postgres stuff. So where can people connect with you?
Lev Kokotov
Yeah. pgdog.dev, top right corner, book a demo. It's not a demo, it's just a call with me. I'm not gonna show you anything that you don't want, I swear to God. It's just a 15-minute call. Uh, I recently signed up for Twitter, now called X.com. I think I missed that whole, that whole saga. Uh, I'm gonna be there probably. Uh, there's a Discord you can join and chat. Uh, GitHub, email.
I think there's my address somewhere. You can send me a letter if you want. That's fine.
Aaron Francis
Perfect.
Lev Kokotov
I don't, I won't, I won't think it's weird.
Aaron Francis
Since, since you're new to X.com, the everything app, I will tell you, sometimes telling us what your username is would be super helpful. So how can we find... Oh, he's looking it up. He doesn't know.
Lev Kokotov
Of course I don't. Hold on. I, I, I think I, I... Hold on a second. I think it's literally levpgdog.
Aaron Francis
You're like, you're like brand new, huh?
Lev Kokotov
It's levpgdog. Literally no spaces.
Aaron Francis
Oh.
Lev Kokotov
Yeah.
Aaron Francis
That's great. All right. Well, I will add a link down in-
Lev Kokotov
Perfect
Aaron Francis
... the show notes. I'll add a link, I'll add a link to everything, um, that I can find, including levpgdog on Twitter. Um, thank you. Thank you for... You look confused. Are you sure that's your username?
Lev Kokotov
I'm signing into Twitter, sorry, X.com, to validate, to check that it, it is, and I think, I think that's right. Hold on a second. I swear I'm gonna get better-
Aaron Francis
What are the likes?
Lev Kokotov
... at this. Uh, but I'm an engineer first.
Aaron Francis
Oh, flawless. No notes whatsoever.
Lev Kokotov
It is me, confirmed.
Aaron Francis
Okay. levpgdog. Great. So we will have a link to that and, uh, everything else down in the show notes. Lev, thank you for doing this. This has been a lot of fun, and I look forward to following along and seeing how PgDog does.
Lev Kokotov
My pleasure. Thanks for having me so much, Aaron. I really enjoyed it.