Autoscaling is a simple concept. Automatically add resources when needed, and automatically shut them down to avoid paying for excess capacity. How hard could that be? If you've set up Autoscaling yourself, you know it's not that easy, especially using the native Autoscalers on platforms like AWS and Heroku. That's why you need JudoScale.
JudoScale is Autoscaling as a service, and they make Autoscaling simple and easy, as it should be. You can use JudoScale on AWS, Heroku, Render, Fly.io, and more. It's free for low traffic apps, and unlimited plans start at $25 per month. Autoscale on Easy Mode at Judoscale.com. Hello, and welcome to another episode of The Bike Shed, a weekly podcast from your friends at Papa about developing great software.
I'm Joel Kinville, and today I'm joined by Adam McCray, the founder of Judoscale. Hey, Joel. Thanks for having me. Together we're here to share a bit of what we've learned along the way. So Adam, what's new in your world?
A couple things come to mind right away. So the most significant thing that's new in my world is that yesterday we had the worst production outage we've ever had in the nine-year history of Judoscale. And I'm happy to talk about that more, but to start on a more fun note, the other thing that's new in my world is we're having a garage sale. I don't know if that's a universal thing or if that's an American thing or not, but basically we take all the crap in our house that we don't want anymore and put in our garage and try to sell its people as they come by. And it's my two daughters who are 18 and 20 years old who decided to do this.
They're owning the whole thing. They had a bunch of stuff they wanted to get rid of. And so yeah, it's super fun just like watching them work together on this thing and have fun and we haven't had a garage sale in probably 15 years or something like that. And it's not something I ever thought I would do again, but they're running it. So it's great.
The joy of delegation. Yeah, absolutely. And they call me in for help now and then. But yeah, for the most part, they're owning the whole thing and having a lot of fun doing it. So it's cool to watch.
Do you put out signs of neighborhood or anything like that? They did. They did. That was all them. They put a bunch of signs on.
I don't even know where all they put signs. They left the house with a lot of signs. And we've had good traffic today. It's actually it's wrapping up just now as we record this. So today's Friday and then they're going to do it again tomorrow and Saturday.
But yeah, they've got rid of a lot of stuff today. So I think they're pretty happy with that one so far. Excellent. You mentioned that you had one of the biggest production outages at Judo's scale. Yes, indeed.
How are you feeling on the other side of that? It was a pretty rough day yesterday. Yeah, I got to my computer around 9.30. I'm yesterday morning to find that our upscaling, auto scaling had not been working for the past 11 hours. And the learning that we had in place didn't notify us about it.
So Carlos on my team, he had logged on an hour or two earlier and saw 30 messages in our support queue and usually just one or two immediately knew something was wrong and updated our status page and was able to get things working pretty quickly. But pretty embarrassing. And yeah, just to have let our customers down in a big way like that, it's just sort of torn me apart. It was a rough day and I'm still recovering from it today, for sure. Was it an easy fix to figure out what had happened?
Not super easy. So I wrote up a whole post-mortem that goes into some more technical details on our blog if anybody wants to check it out. But to kind of give a brief overview of what happened is a piece of unexpected data. So we consume a ton of metrics from all of our customers. They're request queue data and their job queue data so that we can auto scale their services.
And we received some metrics that rather than being a recent timestamp, a very far future timestamp, which shouldn't be a big deal. We should just ignore that as meaningless. But we didn't ignore it as meaningless. We ingested it. And unfortunately, the way our auto scaling algorithm was structured that confused things and broke auto scaling for everybody.
So the fact that that could happen at all, the fact that one customer's data, the fact that the auto scaling of other customers is obviously inexcusable and a really embarrassing experience for us for sure. So it was honestly as hard as it was to write the whole post-mortem of it. It felt a bit therapeutic just to be transparent about it. Here's all the ways in which we screwed up and how we're going to try to fix it. Because I felt like once I just accepted, OK, this happened and I cannot change that it happened.
OK, so what is the best thing we can do to move forward? And it was just to be completely transparent about what happened and own the mistake. And for the most part, our customers have been super understanding and supportive of us. So I appreciate all of that. And I feel like we're making the best of a terrible situation.
I feel like I've been sort of the inside for enough different outages where I definitely feel a lot of empathy for teams who are going through something like that. But I do really enjoy reading the post-mortem document. I always walk away having learned something. So I always appreciate when teams share a post-mortem publicly because that feels like a really a service for the entire dev community. For sure.
I feel the same way. And that's why I definitely wanted to write it up myself and go into the full technical detail of what happened. Our customers are all developers. Our audiences are all developers. So I know I know they're going to appreciate that even if they're a little taken aback by the dumb mistakes we made.
And that's on your blog. And we'll link that in the show notes for any listeners who are interested in digging into the details. Cool. So you sort of mentioned some work with JudoScale. For those who are not familiar with who JudoScale is or what you do, can you give us sort of the quick elevator pitch of what kind of work you have?
Absolutely. I always start with what is auto scaling because if you're not familiar with auto scaling, what JudoScale is going to make any sense. So auto scaling is just the automatic provisioning and deprovisioning of servers so that you're only handling, you know, so you're only paying for the resources you need and you have the resources you need when you need them. So JudoScale is an auto scaler. Basically a drop in replacement for like Heroku's native auto scaler or AWS's native auto scaler, taking a bit different approach in terms of the metrics that we track instead of high level system metrics.
We're looking at actual job queue metrics, actual request queue metrics that are more directly tied to capacity. So we can auto scale apps more effectively. Or you mostly scaling. So like the number of workers for job queues? Or do you also do web servers?
Web servers and job queue workers. So yeah, we started out on Heroku, you know, initially just auto scaling web dinos on Heroku then added the ability to auto scale worker dinos, you know, watching job queues and then just in the past two or three years have expanded beyond Heroku to render AWS, railway and fly. So you find that most of your customers are using JudoScale to scale their web dinos or to scale their workers in the background. It is pretty evenly split. And it's kind of surprising to me the number of customers who might only use us to auto scale their worker dinos.
And I think what we'll see in a scenario like that is a lot of companies web traffic just doesn't change that much. It's fairly predictable. They know the capacity they need and they just leave it at that capacity at all times so they don't feel the need to turn on auto scaling. But job queues are almost never consistent. You know, job queues, the jobs come in bursts.
There's quiet time. So we see all across the board, but definitely have a good bit of customers who are only using products for the worker auto scaling. I feel like that would have been sort of my instinct. Again, like you said, the idea that you have a good sense of what your traffic is, but background jobs are often very inconsistent. And so that's definitely the first place that comes to mind for me where I would like auto scaling.
How much experience do you have working with like different auto scalers with like the dot-pot clients and things like that? It varies. The last few projects have not done any auto scaling, but I have done some of the past that have. Using what I think was the old version of JudoScale, Rails auto scale? Right.
Yeah, I guess I should mention we used to be called Rails auto scale and we rebranded in 2021 to JudoScale because we used to be Rails only. So started out as Rails auto scale. Then we decided to support Python and node the name Rails auto scale didn't fit so much anymore. So today I'm excited to have you on the show because you have a lot of experience managing queues and performance. And I want to dig a little bit into sort of how to get the most out of your queue as a web application developer.
And I think it's interesting to me is queues as a sort of structure are to a certain extent self-balancing. So if you have a few workers, you're trying to sort of evenly split work between them. If you put a queue to feed work into them, they'll sort of make sure that all of your workers are sort of constantly doing work and none of them are sort of sitting idle while others are working. And that's like a really neat attribute of the way the queues work. Yeah, I totally agree.
And to kind of turn that around and give an example of queues that aren't self-balancing. So even on the website, you've also got queues. If you're running two web dinos, requests can queue up on each of those dinos while they're waiting to be processed. But requests coming in, they're being distributed by a load balancer. And so depending on how those requests are distributed, you might get one web dino with a backed up queue because somebody had some slower requests whereas the other one doesn't have a backed up queue.
So yeah, it becomes very unbalanced whereas a job queue is self-balancing in that way, which is very nice. I guess the idea there is having a single queue which multiple processes pull from. And that keeps the work sort of as efficient as it can be, it keeps all the workers at 100% capacity all the time versus if they each have their own queue, one could be idle while the other one is backed up. True, true. Although I will say that we actually tend to advocate for, assuming you don't have a lot of queues.
If you only have maybe three queues, the simplest approach is to have three separate processes, each consuming a single queue. And it might seem inefficient for kind of the way you just described. Because like, oh, what if you only got work coming into one queue and you've got all these processes running that don't have any work. And that's when we would say, well, auto scale those down to zero so that they're not consuming any resources until work comes in. Now, that only makes sense if those processes are handling work with not a very short SLA because when you're scaled down to zero, you have to spin up any resource and it takes some time to start up.
So if you're expecting jobs to be completed within seconds, you wouldn't want to scale it down to zero like that. But it can often be just like an easy fix for some complex interactions of different queues to just say, well, just isolate those queues to its own process. And it'll let you identify where bottlenecks are. You can tweak the resources for each one. Maybe some require more memory than others.
And rather than having one type of machine to process them all. So that solution is not for everybody, but I do think it can be an effective approach. And that's definitely something that's I think really interesting to think about when you're designing the separate queues, sort of customizing them a little bit for the type of job that you're running into. And I was on a project recently where we had to process large files. So it's a very memory intensive task.
And then we also had to send out OTP codes for people who are looking to do two-factor authentication, which is a very sort of quick thing. But also, you don't want the person on the other end of that to be waiting a long time. So that has a very, it needs to complete very quickly. Putting those two things into one queue leads to not very great results for anybody. Right, right.
And it's really hard to optimize the queue because are you optimizing for sort of high throughput, small tasks are optimizing for large tasks to take a lot of memory. And so we found that splitting queues is where things were the most useful. Yeah, we've really been, I mean, not just us, it's becoming more and more common to advocate for SLA based queues, where instead of giving a queue a fairly ambiguous name, like high, low, urgent or something like that, which communicates a little bit of intent, but there's no specificity to it whatsoever. We've really been encouraging our customers to name their queues things like within five seconds, within five minutes. There's a few advantages to that.
One is if you are writing a new job and you're deciding, you know, which queue does this job belong to, it's a business decision at that point rather than a technical. And it's like, well, how quickly does this job need to run for something like a two-factor off-code that you're sending out, customer sitting waiting for that. So that is clearly within five seconds would make more sense for that. Whereas, you know, processing a file that nobody's sitting waiting on, you know, that could be within five minutes, that could be within five hours, depending, you know, you can slice it anyway you want, but it offers a lot of clarity when you're deciding which jobs go into which queues and then not to be the auto scaling to death. But then it also gives a very clear idea of when you auto scale that queue, you know, what is what is a reasonable auto scale threshold?
Well, if the jobs in this queue expect to be processed within five seconds, then you want to scale up if the queue latency, you know, gets to be five seconds or maybe even less. Maybe you want to trigger it at three seconds or something like that. But there's those two concepts tied together really nicely. Yeah. So sort of enforcing that SLA automatically with an auto scaling process.
Exactly. And something like that you mentioned, we have like, let's say three queues for different SLAs, you might have multiple workers that are pulling from that queue. And that's where the auto scale would be scaling up the amount of workers. Yeah. And as if a burst of jobs comes in and you're latency on that queue, you know, creeps above that SLA that you've set, all of a sudden, you know, more workers are going to come to life, bring the queue, latency back down.
And then once you don't want to settle down, those workers can go away. Have you ever tried to debug an issue in production while switching between your error tracker, log viewer and APM tool? Maybe you know how painful it is when you can see the error, but can't find the relevant logs or when you see slow performance, but it can't connect to the root cause. Scout monitoring is all in one platform, built to make your life easier with log management, performance tracking and error monitoring coming soon. All of your data will be together at last.
You'll go from bug to fix in one place. The result, less context switching, faster debugging and monitoring that actually helps you ship code instead of distracting from it. No DevOps team, no problem. Scout works with your existing stack and gives you insights in five minutes, not hours, from bug to fix in one place at ScoutAPM.com. What sorts of signals can you listen to as part of auto scaling?
Is it just the queue depth or other signals that you can plug into? So what's most common is actually CPU. Like if you were to plug in just, you know, basic AWS auto scaling, CPU is the metric most folks are going to reach for by default just because it's there. And it just really does not translate well to queue capacity whatsoever. So with JUDAO scale, we do not look at CPU at all.
We try to only look at queue latency. So queue latency versus queue depth is an interesting thing because the numbers are correlated. So as your queue backs up, obviously the queue depth, the number of jobs increases and so does the queue latency, how long those jobs have been waiting. So you can use either metric, but it's the latency that translates directly to the SLA. So it's really hard to know like, well, is a thousand jobs in a queue good or bad?
Is that okay? Well, who knows? It depends on how quickly those thousand jobs can be processed because maybe they can be processed all in one second, or maybe it's going to take many minutes to get through them. So yeah, we try when we can to lean on queue latency or queue time, however you want to think of it as the metric for auto scaling workers. And I think we're able to do that for most of the job adapters that we support, certainly all the main ones in the Ruby community.
But there are a few job processors in Python and know that there's no way to get to the queue latency. So we do use queue depth instead for a few scenarios like that. When you're talking about queue latency, is that how long the oldest job in the queue has been waiting? Is that average? The oldest job in the queue.
And that gives you a sense of sort of how backed up things are. Yeah, if you've got an SLA of five seconds on a queue and the oldest job in the queue has been there for five seconds, you know, that's not a great place to be. You're pushed right up against that SLA and probably need more resources to process through that queue. Is there a world where maybe the oldest job has not been there that long, but because there's a big burst of jobs, the queue depth has sort of jumped up really suddenly. And so there might be a problem coming up that you can't see just through that latency number.
Oh, that's a good point. Yeah. Yeah. And I guess in that case, maybe you could auto scale more quickly if you were looking at the queue depth, whereas looking at queue latency, you're waiting for the latency threshold, you know, to pass. So yeah, I can see a world where a very specific use case where you might want to use queue depth.
And actually within Judo scale, we let you choose either one. We just try to steer you towards queue latency because we think it's generally the better metric to use. But yeah, you make a good point that, you know, depending on a specific use case queue depth might be more useful. I can imagine though that the latency catches up pretty quickly. So if I dump a thousand jobs into a queue and like the first two or three, the latency is still relatively low.
So it's not auto scaled up, but like by the fourth or fifth one, you can tell where things are going and then you auto scale. So that's probably the one that gives you the more consistent keeping you up on that SLA. I think so. Certainly when we're talking about if we're using just five seconds as a hypothetical SLA for a job queue. Yeah, even if you burst a thousand of jobs within five seconds, your queue latency is going to hit that five second threshold.
So that's pretty quick. If you're looking at more of like a longer SLA a minute, five minutes or something like that, at that point, and you get a burst and you know, your queue backs up, you might have a really high queue depth and your queue latency is increasing, but it's going to take a minute or five minutes before your queue latency is that threshold. So in that case, I would still say that's okay because if you've said your SLA is a minute or five minutes, it's okay to wait. You know, that's the whole point, like because it might, you might work through that queue within that time. So it would be premature to scale up.
So I guess it's the other value of having an SLA as part of the name of your queue is that it sort of gives you a North Star metric on how to optimize everything else. Instead of just a gut sense of, oh no, the queue seems to be getting too deep or maybe we're running out of CPU, you say, Hey, if we're hitting these metrics, that's SLA, then we're fine. I think I first read about this concept, maybe on the gusto blog, or maybe it was something that Nate Birkapack shared. But when I first heard about this idea of like SLA based queue names, it just felt so obvious. I was like, wait, why haven't we been doing this?
We've been naming our queues, things like high, low, or maybe even something more domain specific, like email or like, you know, that just don't really communicate anything, all that useful when it comes to, when it comes to scaling or when it comes to, you know, how to choose a queue for a new job. So yeah, the latency based queue just offers a lot of clarity there. So we've been talking about sort of segmenting queues based off of SLA. Do you ever find yourself recommending segmentation based off of other metrics such as maybe something that's really high CPU usage or something that's really high memory usage? Definitely.
Yeah. I tend to think of that as like the shape of the job. You know, does the job consume a lot of this? Is it high IO? Does it consume a lot of CPU?
Does it consume a lot of memory? So with Ruby's GDL limitation, if you have, you know, 10 jobs running concurrently that are all running Ruby, only one of those can use the CPU at a time. So there's going to be contention for the CPU and all of the jobs are going to take longer to run as opposed to if they're all just doing IO than while they're waiting for IO. The other jobs can run. So due to that shape of the job, you're going to scale them.
You're going to see, not actually going to scale those queues in different ways. More about how you configure those queues in that case, like how you set your concurrency use. And likewise, when you mention memory, yeah, if you have certain jobs that require a lot of memory, that might force you to use, you know, beefier machines, you know, to go back to the Roku example that might take you from a standard 2x dyno to a performance dyno, which is five times the price, but you only need it for this one job that consumes a lot of memory. And in that case, what I would often recommend is to quarantine that job to its own queue or maybe have a specific high memory queue, which is where your high memory jobs go and have a separate worker process that handles those jobs so that you can just throw the expensive hardware at those jobs and not waste the expensive hardware on the other jobs that don't necessarily need it.
That makes sense? Yeah. And like you said, one of your options when you are auto scaling is you can auto scale down and you can auto scale all the way down to zero. And so if you have something that's infrequent, but high memory, maybe you get a more expensive machine that comes online just for the 10 minutes it takes to run that process and then shuts down all the way to zero. Yeah.
That's probably one of the most common questions that we get regarding, you know, job queue setup is you have we have this one job that consumes a ton of memory and, you know, it's forcing us to use performance. Dinos, how can we manage our costs? And yeah, this is the way assign that job to its own process and scale it down to zero, especially since these jobs are often batch processing stuff that happens overnight or something like that, that like it just doesn't need to be on all the time. And when jobs come into that queue, it's okay if it takes 30 seconds to fire up a new, a new dino and a Ruby process to start working through it. So yeah, that can be a really good solution.
I feel like the idea that you can auto scale down to zero rather than down to one is something that's non obvious. What are some other uses that you found without ability to go down to zero on a process? It's very useful on non production environments that are being used all the time. You think of a staging environment, a QA environment, a demo environment, something like that, where you just, you know, you don't want to pay for resources running all the time for environments not being used all the time. So we see a lot of that.
Yeah, and those are the two big use cases. Yeah, an infrequently used environment and then, you know, a dedicated queue, you know, with a low SLA with a longer SLA, you know, if it's a minute or more SLA, that's the spin up time to start the machine matters less. So yeah, dedicated queues for those lower SLAs scaling those down to zero. It's easy way to save some money and still hit your SLAs. I feel like there's so much you could understand in terms of queues and how to optimize them, how to split them up, when to combine them together.
And I know there is some formal theory around queuing theory. Have you dug into that much or studied that yourself? I've not. No, you know, brief interactions with chat CPT trying to brush me up on queuing theory. But to be honest, like the little bit that I've learned, I haven't found ways to apply it to basic job queuing stuff like we're talking about.
I couldn't even tell you what queuing theory entails. I don't know how much have you looked into that at all? Very little. Although I was reading an article and unfortunately I lost the link to it. So I don't think I can share it in the notes.
Just look at mathematical modeling, sort of what a queue is. But something that was really interesting that came out of that mathematical modeling is that if you don't deterministically know the work you have ahead of time, you can never perfectly match the resources you have available to the work. Thus, the only way you can avoid backing work up is to over-provision in a static environment. Right, right. I went through this and I was like, oh, that's why we have auto scaling.
But it was kind of fun to see that shake out of a very sort of formal mathematical definition of queues. Yeah, yeah, that is fascinating. Over-provisioning is certainly the most common solution. If you've got money to throw out a problem, it's an easy solution. But even over-provisioning is how much over-provisioning is enough.
How do you know when you're going to get that burst of work that even what you thought was over-provisioned wasn't provisioned enough. So it still feels like guesswork if you're not automating it in some way. Right, right. That's like, oh, is 20% over capacity? Is that something we just sort of maintain?
I guess you can have an ops person who sort of keeps a close eye on all these things and gets a pager alert when you get near a threshold and manually scales things up or down, which is I guess just getting a human to do the job of Judo scale. Yeah, I think Judo scale will be a little cheaper than that. Having a dedicated ops person that can be paid? Yeah. Is that a job that you've done?
Not specifically being paged to tune queues up and down. The origin of Judo scale, which was then Rails Auto scale, was a company I was working for at the time in 2016. It was more about saving money. We were just running a whole bunch of resources on Heroku that were only being really used certain parts of the day and wanted to auto scale that to optimize our costs. It was only later that we kind of turned our focus not just to cost savings, but to the quality of service optimization just to make sure that not every company is all that concerned with cost savings.
It's more about we want to deliver the best experience possible for our customers at all times. Yeah, it serves both and it's always become a marketing challenge for me. We focus on the cost savings. Do we focus on quality of service? Ultimately, try to focus on both.
I feel like that's a little bit where that SLA base queue idea comes in that what you can say is it's now you have an automated guarantee behind that SLA instead of it being sort of mostly suggestion that your does will try to keep to now. You know, we've got automated systems that will guarantee that SLA for you. Yeah, to what you said about, you know, it can get really complicated, you know, trying to figure out what queues you need, how to blend them together and how to prioritize them. If you can just choose three SLA base queues and just wrap all your jobs to one of those three queues, it can simplify a lot of things. And if you're not sure how to combine those queues and prioritize them on a single worker process, well, then just isolate them on the worker processes and that is an even simpler way to set it up.
So you mentioned three queues several times already. Are there three numbers that you like to aim for when you're setting up a new system? For us, we like within five seconds within five minutes within five hours. You know, you can choose whatever numbers you want. I just like the consistency of those and if you know, they just flow really well together.
And I feel like those three buckets captures almost any use case that I've seen any use case is going to fit, you know, either needs to happen really quickly within five seconds or needs to happen within a reasonable amount of time. And they'll be sitting waiting on it. So within five minutes or, you know, nobody's it's an overnight thing. It doesn't matter within five as long as it completes within a few hours. It's fine.
So those three have worked really well for us. If I'm a developer and I've been working with a system that has had to use, that I've been backing up or jobs that haven't been processing quite right, and I'm not sure that just scaling up is going to be the right solution. What are some of the dimensions or like metrics that I should be looking at in terms of like these are things that I should be monitoring to get a sense of what I need to change to improve my queue? I know you mentioned CPUs, a classic one that you find is maybe not as useful. No, I would say, you know, even if you're not auto-sailing on it, queue latency is the metric to watch.
So if you can hook a queue latency up to whatever you're using to monitor metrics, you know, whether a data dog or whatever have you, if you can watch your queue latency over time, it'll become pretty clear if you've got a problem. You know, you might see one queue that, you know, shoots up to, you know, several minutes of latency and you know, like that. That queue has some important stuff in there that should not be waiting minutes. And you know, that'll point you where to go for sure. What about for more once you know, okay, I'm having latency issues on this queue.
Let's say the problem was that I'm mixing jobs with different shapes in the queue. Are there other metrics you might want to track to get a sense of when the shapes of jobs in your queue are sort of too heterogeneous? I guess, yeah. I mean, I do think CPU might be helpful there because if you see that your CPU usage is really low even when your queues are backing up, that probably tells you you can crank up your concurrency a bit. These jobs are probably doing more IO and you can handle more simultaneously.
So yeah, CPU is definitely good to keep an eye on. I just, I just definitely wouldn't consider CPU in a star metric, but CPU is good to watch, you know, watch your memory, especially on a platform like Heroku where memory is limited. If you start creeping into swap memory, it slows everything down. We get a lot of questions. The boundary on Heroku between a standard 2x dyno, which is a gig of memory and the next step up of performance M dyno with two and a half gigs of memory, there's a huge jump in terms of price between those.
It's $50 to $250 a month. And so, and it's such a one gigabyte is such a common point where rails applications will push up against it, get close to it and then, you know, we're just over it and we don't want to have to jump to these super expensive dynos. So yeah, watch your memory. And if you find that your memory is creeping up there, well, the next question is, okay, which, which jobs are causing this? And actually just saw today that make Birkapek released a new gem, I think it's called Psychic Memory Profiler.
I think it's just that, which will let you track memory usage per job over time. So I have not used it myself yet. I just saw it today, but that I think is going to be an incredible tool for isolating the jobs that are causing memory issues. And then once you isolate which job it is, you can quarantine that job to its own queue, its own machine, and hopefully see the rest of the jobs on that queue, the memory usage going down. There are sort of a few different job shapes you like to look out for.
And I'm always a fan of a setting up a taxonomy. Do you have maybe, I don't know, three to five classic job shapes that you look out for when you're trying to get a sense of what sorts of jobs are on a queue? Yeah, I would say the three that I look for are high IO jobs, high CPU jobs, and high memory jobs. And sometimes there's overlap. Like memory is sort of orthogonal to CPU and IO, whereas CPU and IO, they're a couple of minutes.
You've either got a job that's high IO or high CPU, or neither is just in the middle and even split. But then in either of those you could have high memory usage or not. So a combination of those creates a few different shapes, but those are the things that I look for. And I guess all those and also combined with different SLAs where you might have a high memory job that has to happen fast versus high memory jobs that have to happen slow. Yeah.
But when I think of the shape of the job, I'm usually not thinking of the SLA because the shape of the job is more about configuring your workers and choosing hardware for the workers and that kind of thing, less so about auto scaling, whereas the SLA is really kind of focused on auto scaling. That's a good distinction. Never find yourself maybe looking at a job that's sort of a composite of a few of these different attributes and maybe it can be decomposed. So you say, hey, I'm going to split this into two jobs, one of which is sort of more CPU bound and I've like split the IO stuff into its own job and now they can happen sort of on different cues. Absolutely.
Certainly, almost always with high memory jobs, that's the first thing you want to look for is how can you split it out into smaller jobs. If you are iterating through a whole bunch of active record models and processing them, well, can you maybe fan out that job into a separate little job for each one of those records rather than trying to process them in a single job. So yeah, I think memory is the biggest culprit for the big opportunity, I would say, for splitting out a job. Yeah, generally, any opportunity you have to split out a job, I would say split out a job. Always a good idea.
And that's not just for sort of parallelism, but also because then the overhead costs in terms of memory and CPU for each becomes more manageable. Exactly. I guess now you're back into that job shape versus SLA, where like the benefit of parallelism is that you can auto scale more to hit that SLA versus the benefit of pulling out just the memory intensive parts is more around having a single shape to your job. Am I sort of describing that right? Right, right.
And odds are, as you split out one big job into a bunch of smaller jobs, the shape changes. This big job is suddenly not such a big job anymore because it's just in queuing a bunch of other jobs and hopefully that happens quickly and doesn't consume a lot of memory. So you're changing the shape of your jobs. And hopefully that makes it easier to scale. It means you don't need the more expensive hardware to do the processing.
You're also reducing the opportunity for one job to become a bottleneck, depending on your concurrency and how many of these big jobs you have come through the queue. You don't want a few large, long running jobs to be a bottleneck and prevent other jobs from coming through. And by fanning them out, slitting them out into a bunch of smaller jobs, then maybe they're on different queues, maybe they're on the same queue, but it's not a scaling process. So you get more processes working through all those smaller jobs rather than one process just cranking away on one big job. The mixing of slow and fast jobs I think is the easiest way that I've found that I get myself in trouble with queues.
Yeah, I think that's fair. And that is a tough one because, yeah, slow and fast jobs we haven't really talked about much. And I was not talking about shape, but we're talking more about CPU, memory and IO and SLA is more about expectations. But yeah, slow and fast jobs is another way to look at your jobs. And certainly slow, long running jobs can be dangerous.
They can become a bottleneck. They can also become issues when you have server restarts or anything like that. If the job is not idempotent, you have issues because the job gets partial through and then terminated and then restarted. And the easiest way to avoid that is just to not have those long running jobs to begin with and split them out into a bunch of smaller jobs. That makes a lot of sense.
Thank you so much for coming on the show and chatting all about queues. As we wrap up here, if you had one piece of advice you could give to web developers who are working with queues and background jobs, what would it be? I mean, we've hit it pretty hard in this episode, but I would say start with three queues named based on the SLA and see how long you can stick with that before you need to create a fourth queue. And that is a great set of advice. Adam, thank you so much for joining the show.
This has been really fun to dig into queues and to sort of look at all the different levers we have to pull on when it comes to optimizing performance. Yeah, thanks for having me, Joelle. On that note, let's wrap up.