The Pragmatic Engineer
00:53:14 · Gergely Orosz, Maude Lemaire
[00:53:14] S2: Across all of GitHub. [00:53:16] S1: Across all of GitHub. Only 16, which is not very many given the amount of data that we know is associated with that whole space. And my first question was like, wait, why do we only have 16 charts? Oh my gosh, this makes me deeply, deeply nervous. And part of the answer was, we can't have more because we already have so many scatter queries. So those are queries that are coming in. [00:53:43] S2: What are scatter queries? [00:53:45] S1: So those are queries that are coming in where you do not have the primary key in them. So say you are querying for a pull request or an issue, and you don't have the pull request ID, which is how this data is being distributed. Well, you have to find it. So you have to go... You have to find and match the criteria. So say I'm querying for all pull requests authored by me. I don't know that that's an actual scatterer, but this could be in the scenario. Let's just assume. And so because I don't have a pull request ID, well, I'm going to hit every single one of those 16 shards. [00:54:23] S2: Wow, this will be bad in so many levels. [00:54:27] S1: Uh-huh. Because, well, so many people are doing it also. [00:54:29] S2: And I understand then why you don't want to have many shards because if you have more shards, you would need to hit all of them. We're talking like, it's almost like a linear scan.
00:54:29 · Gergely Orosz, Maude Lemaire
[00:54:29] S2: And I understand then why you don't want to have many shards because if you have more shards, you would need to hit all of them. We're talking like, it's almost like a linear scan. [00:54:37] S1: Yeah. Yeah. Oh, no, it's quite, quite, quite inefficient. And again, I don't know that this is an actual example of one of the- This was hypothetical. This is completely hypothetical, but there were still very many significant scatter queries that were hitting almost every single shard before it knew that it could complete the query and return the result. Which, yes, I understand why that was a constraint then. You don't want to add more shards. But then again, you also cannot make the shards much bigger and they're under very heavy load. And so I was ready to apply the playbook that I'd been using for the last several years of like, well, let's [00:55:12] S2: just burn down the scatters. Let's just get rid of the scatter queries. Don't have scatter queries.
00:55:12 · Gergely Orosz, Maude Lemaire
[00:55:12] S2: just burn down the scatters. Let's just get rid of the scatter queries. Don't have scatter queries. [00:55:17] S1: Just don't have scatter queries. That can't be that hard. Well, it turns out that can be very hard when you're dealing with a... Rails, Monolith, and you've got ActiveRecord. And I always sort of thought it was funny, the number of, there were a lot of ex-Twitter folks at Slack early on, and everyone was like, haha, ActiveRecord. And I was like, what are you, like before they did the whole like Scala Java thing, right? And I was like, okay, I guess like we're all, you know, joking about ActiveRecord. I did not understand. Yeah. Until I like came face to face with it and I was like, oh, I really don't like this. This is really terrible. [00:55:54] S2: So like the record is Rails' abstraction layer for the database, right? So you define things in, I guess, code and it kind of maps nicely to database, except it might be harder to fine tune your queries, et cetera.
00:56:08 · Maude Lemaire
[00:56:08] S1: Yeah, I mean, it does a very good job at hiding the underlying data model from you, which, again, pros and cons. I came from a world where, like, SQL was, you know, religiously written out by hand for performance reasons. And then I was being... Thrown into this world where at one point we were trying to figure out, we were doing a bunch of work around domain extraction. And so how do we rip out everything related to, say, pull requests from the Rails monolith and extract that into a separate Go subsystem, take everything that deals with pull requests, just make the requests go through, say, the monolith still, but then just immediately send them over to the other system. Really standard sort of migration procedure. Started doing that. We started with stars and I think that project was eventually abandoned, but I was working, I was pairing with someone who had like a ton of Rails experience. And I was like, okay, you gotta like, because I, as someone who was so used to reading just code that was very sort of straightforward and didn't have so many levels of abstraction. It's a little bit daunting when you're going into a world where now there's abstractions upon abstractions upon abstractions. And I was working with her to try to rip out more of the STARS-related queries inside of the Rails model. We'd found sort of the root caller that created this query that would call into the STARS table. And it was like a five-line function. And I was looking at it with her on Zoom. And I said, wait, Kate, where... Where is the call? Like, where is the sequel being made? Like, what is happening? It's a five-line function. And she's like, Mo, that's the million-dollar question. And I was like, what are we looking at? What is happening? Because I half expected to see... I mean, at this point, I think so many people use Prisma, right? And Prisma, you can sort of... It's not, you know... Plain SQL written out as a string between quotation marks, but you can sort of see the structure of the SQL query being made. You do not get any of that in this case. It just looks like a regular function call. And in that moment is when I realized this is why this has been impossible to date. And why the problem has gotten so bad, because no one sees the impact Just writing a new line of code.
00:58:39 · Gergely Orosz, Maude Lemaire
[00:58:39] S2: And also fixing it now will probably, it's not as easy as just tweaking your abstraction layer. You would probably have to change how code is being written, being called, starting to call more either functions that call SQL, et cetera. Like it's just, you took a technology that worked great when you were small, you were able to scale it as long as you, and they figured out how to grow it as long as things are going linearly. [00:59:04] S1: Yeah, and I think one of the things that blew my mind the most that both gave me a lot of respect for how they've managed to date and also filled me with much dread was when you work inside of GitHub, obviously you have the admin view of GitHub and there's this bar at the top where you can load up a page on GitHub and it'll tell you exactly Wish MySQL queries were run to populate the page, which clusters they hit, how fast they all were, totals around all of this stuff. [00:59:38] S2: Just like the internal employee view. Yeah. [00:59:40] S1: Yeah, yeah, yeah. And what's called the files disambiguated page, which is sort of like the repo homepage that you land on with the readme. That page last I checked before I left. [00:59:51] S2: Before you left like a year ago?
00:59:51 · Gergely Orosz, Maude Lemaire
[00:59:51] S2: Before you left like a year ago? [00:59:52] S1: Actually less than that. But yeah, yeah, yeah. So some amount of time ago, it was over 100 MySQL queries to populate that page across at least three different MySQL clusters. And the thing with ActiveRecord is that it only caches the output automatically if the query is exactly the same. And so if, say, you're fetching user information, like full blanket, like select star from users where user ID equals blank, and you have that full user, but then later on you do select star from users where user ID equals blank and something else, it's not going to reach back into the results that it cashed for that first query because they are not exact same queries. Every single count. Or at least when I last left. Almost every single count you see on a GitHub page is live calculated. None of those are cached. There's a lot of reasons why that is. Mostly product reasons, actually. But that's one of the first things that I was like, but why? And to go back to like my sort of silly emoji example of like the 10,000 in month emoji, no one cares. Why does anyone care, right? And if you have low counts of things, sure, okay, maybe it matters that there's three open pull requests on like this very small repo that like no one really does anything with. But once it gets to like 99, don't just, don't show anything, just say 99 plus. Don't bother counting it. Why are we counting this?