Rails World 2026: Durable orchestration on Rails: from continuation to workflow (Vladimir Dementyev) Video: https://www.youtube.com/watch?v=4dcv1a7eeMk Talk page: https://www.rubyevents.org/talks/durable-orchestration-on-rails-from-continuation-to-workflow Unedited machine transcript, generated with Whisper. It contains recognition errors (names, technical terms). Check the video before quoting. ---- All right. Hey, everyone. Glad to be on the Railsforce stage again. Thanks to Amanda, the Rails Foundation and all the organizers for making this conference a once-in-a-lifetime or twice-in-a-lifetime for someone, maybe last-in-a-lifetime event and experience. My name is Vladimir, and I've been building with Ruby on Rails for more than 10 years and about the same amount of time I've been contributing to Rails. And over the years, I've managed to publish a lot of gems. You probably know a few of them. Some of them were mentioned. Even wrote a book you probably read or your agent read. Ask it, by the way. Is it good? And most recently, my Rails contributions were all around Action Cable. And for the next release, it's been re-architected to support different server implementations without hacks, like as Async Cable, the most interesting one. And on top of that architecture, some fixes and improvements have been already prepared and also expecting to land in the future releases. But that's not what I'm going to talk about today because that proposal hasn't been selected. So that's it. Next topic. Sorry. I'm first time using this clicker. So a few words about my job. I'm leading a backend team full of brilliant Ruby, and not only Ruby, engineers at Evil Martians. Makers are not on my team, sorry. And we're helping startups and companies at scale to ship things, you know, and do that with higher quality. And we also help Rails Foundation since recently. You've already heard about this Rails AI benchmarks project. That's both my primary focus for the last month. And now my nightmares are full of LLM sessions, transcripts, full of shitty reasoning. So I can sometimes recall them when I'm awake. Don't be afraid. But I'm not talking about my job today, luckily. I'm talking about your jobs. background jobs and this is the topic of my talk today and I'd like to start with some a little bit of a little bit of retrospective so I want to show you how the role of active job has changed over the years from 4.2 to 8.2 so it all started in 2014 the same year I shipped my first production rails application and I remember the moment ActiveJob has been announced. My thoughts were like, oh, wow, that's really cool. Finally, Rails ships a background job, a kind of implementation on its own. But I'm not going to migrate to it, because what's the point? It's just a thin compatibility layer on top of the existing gems, and it doesn't add anything and missed a lot of stuff. So, the app I worked back then, by the way, is still alive, and now it's a large Rails monolith, still doesn't use ActiveJob. So, and I've seen many apps like that in my life, unfortunately, but I encourage you if you're still using, I don't know, Sidekick workers directly, please consider migrating to ActiveJob because today ActiveJob is no longer just a common interface. Over the years, gradually, slowly, it's been evolving. It was bringing new solid ideas until we got to the point where a year ago, a new concept not present in background job engines appeared in ActiveJob itself. So the framework finally started bringing something specific on top of other works. And let's talk about Continuation for a moment. What is it and why it's important? So Continuation is, by design, a resilience concept. It was added to make long-running jobs interruptible and resumable. by introducing steps and cursors that act as checkpoints. And the original motivation for that was surviving deployments. And you can find it in the original PR. That's the actual reason why the feature was brought to Rails. What does it mean surviving deployments? Let's imagine the same WebCube dispatch job from the previous slide, but without continuation. It looks pretty similar. Same shape, same logic, but different guarantees. Whenever deploy happens in the middle of the iteration, the job is dropped, and it's retried by the background processing engine. But it starts over the iteration from the first step and could result in sending the same webhook event twice. So it's not cool for your application. That's why, for many years, we've been using some workarounds like this one that's the most popular, having several jobs. queuing atomic jobs per record so making this approach robust or reliable maybe a bit more verbose and less cohesive than a single job version but it worked now let's again compare it to the continuation version we have everything in one place we have the same guarantees and we have the whole workflow let's call it a workflow defined in a single file and to my taste it's much better than having it scattered across files it's more resilient to human or agent errors, whatever you prefer. So this is a canonical example of using ActiveJob, and this is what it was created for. Now back to the timeline. So as I already said, ActiveJob started as a tiny facet over other runtimes. But over the years, it evolved into a foundation of its own. And together with SolidQ, which is an important component of the ecosystem today, they lead the way for everyone on how to implement background jobs and maintain them on Rails. But what's coming next? What awaits us in the next version? I picked some PRs to ActiveJob, some merged, some not yet, but the most interesting because they bring in new staff to ActiveJob. And half of those PRs are continuation-related. And what's more important, they contributed by the community members, not by the core team, or by the core company team members. So, and that's an interesting fact, because continuation is just a year old, but it's being adopted quickly. But the way regular users, like not the ones contributed originally, use continuation differs from the original intention. It's no longer about surviving deployments. It's about orchestrating long-running multi-step operations with their state or with their kind of guarantees that's a snippet I use a lot these days to split a long-running LLM related job into multiple steps and run them and isolation so we can more fair distribution of work across workers and that means that the teacher that was born as a workaround for infrastructure quirks actually became an orchestration primitive but this primitive is still too primitive to be a building block for the common job orchestration scenarios. Let's look at some examples how we coordinate multiple background jobs today and what are the common patterns and tools to implement them and how we can use continuation for that, maybe a little bit upgraded version of it. So let's start with pipelines or job sequences. posting files or importing data, syncing, whatever. There were a lot of use cases, but they have similar shape. One of the shapes is a chain of jobs. So we have one job performing the first step of the operation, and on the successful result, we enqueue another job. We can terminate the process by failing it somehow, but then there could be another job. And the number of such jobs in the chain and possibly branching, could be enormous, and it's very typical for large Rails applications. And the problem with that, that no one, you know, in a month after implementing that, no one knows where the start of the chain, how it goes, what is the direction, what are the outcomes, what are the failure modes, and so on. So we can refactor this chain of jobs into a chain of steps with continuation. We can encapsulate the whole workflow in a single place. And this is no longer about interruptibility and resumability, right? This is just about organizing code in the application. And there are some quicks still left because we rely on the states saved on the model to control the execution of the steps, which is not the best way to do that, but we don't have any other states to rely upon. So it's still just a background job running by active job. Another example of the kind of pipeline, Same idea, multiple jobs running one after each other. But now we have actually the single job which is being re-enqueued to perform the next step controlled by a separate state machine. This is an example from our AnyCablePlus project. There is no even background job class visible, right? Because we use active job performs plaguing that just turns a method into a background job. Very convenient. But the problem here is that we have too many entities to orchestrate. the work. And moreover, yeah, so that's how it works. And it could be also written into a kind of step machine to make it more clear what the order of the step, what are the guards for each step. And it could be done today, especially with the addition of this new attributes API that allows us to keep some state during the execution of the workflow. But this state is not accessible anywhere outside because it lives in the jobs payload. limitations another problem that unlike with many things and rails like performing actions and whatever we don't have control flow hooks for steps there are no step callbacks no per step rescue handlers and so on so every step has to deal with it manually like here we do broadcast update in every step because well we need to do that if we had like after step broadcast that would be much better developer experience and much better readability of the whole process. But that's something that's missing today. So yeah, we mentioned a couple of things. And I slightly mentioned that we don't have observability for continuation process. We don't know which step the job is currently in, how long has it been running, what is the history of steps, just because there is no persistent state. And the rules and steps and retries I already talked about. Other thing related to such workflows as uniqueness constraint, for long-running workflows, we typically don't want them to be re-enqueued multiple times while the previous one is still running. Or if it's still running, it's better to cancel it or re-enqueue. But there is no such API inactive job natively. Some providers have something to do with it, but it's not a framework-level concept. And we also need it for many workflows and pipelines. So what about the third-party solutions? been existing for a while this for example acidic jobs we used in couple of projects it introduced a durable state so every thing happening with the workflow is stored in the database we can restore it we can observe it and there is a built-in uniqueness and so on and what's important for me at least that it has active job interface so from the outside color the job is still active job everything you can use was actually drop works and the whole of the workflow is hidden within the workflow class. Another most more recent development is Unix Geneva Drive project. Actually, it comes with almost everything I wish a workflow implementation had. And we're going to refer to it a few times in the talk. But the biggest problem to me, it's not a Rails thing. It's a custom DSL. It's a custom entity. truly compatible with active jobs. So we need to refactor everything to use it. And I wish we had something more kind of framework friendly, but with the same guarantees. OK, next pattern I want to touch a bit is batching. So when we have one job performing the setup, many jobs performing their own task, and then something running on completion. And batches could be actually executed sequentially. Well, we can use continuation for that, and that's, again, an example from the wild work from Spray. We begin processing, we create a job per CSV file row, and then we do some finalization. But actually, whenever we talk about batches, we usually imply parallel execution, right? And that's the problem, because whenever we start parallel execution and we need to coordinate the And of the execution of many jobs, we need some coordinator. And typical coordinators are counters, possibly stored in Redis, and maybe polling. Like in this example, we just have a job that periodically checks, oh, everyone's ready? No, let's try again in five seconds. And for this use case, we typically use third party jams. But the good news is that since very recently, we can use third party jam. Solid Queue 1.7 just got Solid Queue batch support thanks to JP, Camera, and Rosa, of course, helped a lot with that. And it's been a long and winding road to batches in Solid Queue, and I highly recommend to read the story because it demonstrates what amount of effort is required to ship a major feature to corners or library like Solid Queue when you are not a contributor your outside contributor that's massive work and thanks everyone involved into that that's cool so that's just a quick review how does it look everything is a job so whenever we want to run something on completion we create a job on successful failure and so on this interface is inspired by good job that had batches for a while and we had many more examples of batching with everyone come up with their own interface, that's a problem. But still, the problem is kind of solved. It just needs your choice on which library to choose. And I want to highlight the one from Doximity, Simple Kick. It's Sidekick specific, but what's interesting here is that interface is very similar to continuation. We have steps, code runs. We have parallel steps, something that's missing in continuation. But it hints, at least to me, can reuse the same idea of parallel steps probably in continuation. But there is just one blocker. And what's the blocker? We don't have it in ActiveJob. And we'll probably have it at some point, because there were some discussions about it. And as soon as the interface landed in ActiveJob, we can bring it to continuation and make our workflow batches aware. But we need to wait. And speaking of waiting, that's another pattern. of orchestration scenarios that the background tasks that involve all kind of timers like reminders expirations notifications and so on for example again from our end cable project this is a typical flow we have a bunch of recurrent tasks like polling tasks that run every 10 minutes or every hour or whatever depending on the scenario for the same process actually this is a license expiration across multiple background jobs. And each background job is actually an entry point to enqueue more background jobs. And it introduced a lot of, you know, code concepts just to implement a single workflow. We need to repeat it for every workflow. With continuation, it could be simplified a bit because we don't need this nesting. We can use iteration within steps and cursors and limit the amount of job classes to one. still we need the scheduling thing and but that's already it looks better than without it another pattern related to time is a parking job someday in the future with wait or wait until and then executing there but the problem with this approach well actually there are a lot of problems with this approach but first problem is that we usually need to invalidate oh if this job is still relevant because there is no at least active job level api to cancel up in the schedule for the future. Yes, you can reach out for the provider-specific API, but usually that's just a lot of work, and validation is simpler and more reliable. There are many questions related to this approach, but conceptually it sounds good, but technically it's hard to implement, and we typically fall back to the cron-driven sweeps. Let's take a look at the gems that implement something that makes this easier. relatively new project called chronoforge and it's it extends I actually active job with custom let's say the DSL method declarations including wait so whenever you enqueue a job it reads the wait statement and says oh I'm stopped here I add myself to the waiting queue or table and then I'm being re-enqueued when time comes and continue the execution Geneva Drive also has this concept of timers is just an option for the step and it also has this beautifully designed mechanism of associating workflows with models through heroes so you can easily find a workflow associated with some active record model and cancel it when needed that's very useful so there is an ipi for that and another option is actually using third-party services like to borrow a pretty popular one recently it has a lot of stuff and what's interesting here is that that's kind of the same example with appointment reminder but instead of cancelling the workflow and restarting it from scratch when the date has changed for example we can just update the deadline for the reminder so it's also part of the state of the workflow when we want to trigger it so uh kind of related to timers is a more generic group of workflows or features, approval workflows or signal-driven workflows or like human-in-the-loop scenarios, right? So a signal is something that a workflow waits that isn't time, maybe a user action. And typically in code, signal splits the implementation of the workflow into before and after parts, living in different places in code. Like here, it's from Mastodon example. It's the same process. It should be read as one process with a break in the middle, but we don't have a way to implement that in Rails. And given that signal is not guaranteed, we need to take care of cleaning up tasks that hasn't been signaled yet. That adds a lot of ad hoc logic to your application. popular is a webhook event. This is a real example from one of the apps I worked on. And we see that workflow is scattered across three files. So we have the one job that requests the withdrawal. Then we have a webhook that sends the confirmation or rejection. And then finally, we have another background job that processes the result. If we migrate, for example, to ChronoForge, because it also has this signaling feature with continue if step, not an obvious naming. But anyway, we could rewrite the workflow, this one, into just a single perform method with three steps. Run third step, wait for the payment receive, run credit step. And it's much easier to reason about than finding all the logic in between multiple files. But unfortunately, the project, I borrowed this example from, picked another solution to implement this workflow. So it's loading. Yeah. So they picked temporal. And I can't say I'm happy without it. So I don't think implementing such things that could be expressed in English in few words should cost us hundreds lines of code and dozens of Ruby objects and scary voodoo magic to make them all work. So that's the problem. The more complicated, the more sophisticated your workflow becomes, use. And I don't think it's the right way of, you know, going into the future with Rails, right? We need more batteries included. We are missing some of them clearly. And why not adding them? About a year ago at a SAP Ruby conference, which is happening this year again in November, by the way, don't miss out. I already shared this idea that, well, now we have a cool concept for building more than just single jobs in active jobs so we can build something bigger, some workflows. And let's not invest into building custom jams or ugly SDKs. Let's just build on top. Let's turn continuation into something bigger. And I've been keeping this idea in mind for almost a year. And today, I want to present the first implementation of it. So let me introduce the Drupal continuation. for active job all right what is durable by the way what do we mean by that right everyone's talking about that especially since temporal coined this term and started using it everywhere trying to make it look like oh it's something's very special you know it's nothing special the main difference is that basically a job the execution process is a record or multiple records in the database or some other store and not just a payload in the queuing system that's the primary difference. Everyone else is a consequence of it. So like surviving sick kills and so on and so forth. That's just the properties we get if we carefully commit the state and make it restorable and replayable. So to turn active job continuation into durable continuation, we need to implement a few things. The ones I've been already talking about in the previous section, right? Those that's missing. But the most important requirement, which I always add to anything I work on, any library, that it must be as close to Rails way as possible. It must feel like using the framework, not a third-party library. So it should be an extension, not a replacement. Something that could be merged into Rails in the future. If you build your library like that, then you kind of get some kind of style and taste, by default and they usually help you to get with a better implementation so let's move to the durable continuation proposal and let's start with the state so back to the one of the examples this is a also from SF Ruby our cards generation job the previous version the one that generates cute characters based on the photos and it has multiple steps because we need to process the original image first we need to moderate it we do not allow any type of images downloaded and show to everyone in the community. So we have some check there, moderation step. And then finally, we generate the final content. So that's how it looked like in the original version. It's not durable yet. What does it mean to making it durable? And what changes? So we have a table with the execution runs and their state and step state and whatever. and we can see how it's being populated and updated as as the execution progress so first we enqueue the job and we got a record on the table so the process hasn't started yet but we already know that it's being enqueued then as soon as we hit the worker we change the state to running then we update each step as we progress we keep the attributes in the state as well so they also durable So you can observe them from the outside. So you can build some features that use these attributes as data for your other operations. And finally, you have an API to query this data easily, kind of similar to what Geneva Drive has. But we don't have a concept of heroes. We just infer identifiers from arguments or specifically defined identifiers on the job. And you can see what's happening with the job. cancel it if you want or retry or whatever. Let's see how this state, durable state that we add, affect our resumability properties. This is the original webhook example and using continuation. Imagine that we run the job, it triggers webhooks, but then it's crashed and the job restarts and the cursor value hasn't been committed was a heart crash or some exception that hasn't been caught. And we started over because we don't have any memory of what's been in between the steps and within the step. When we switched to durable continuation, just one word changed, right? Nothing changed in the class, just a single model. We have a different picture. We have cursor committed, not every step, actually, but you can configure it whatever you want. And that gives you better guarantees in case of different problems that could occur to your app. So we just improve the reliability of the operation. Now let's talk about the lifecycle and what else do we add to make workflow more useful. Remember I mentioned that while we don't have callbacks, we have to inline everything in our step bodies. And now with durable execution, we also ship callbacks, after step callbacks. that makes your workflow look like, you know, a typical Rails object with all the functionality typically available for models, controllers, whatever. It's no longer just a tiny wrapper over background job execution. Similarly, we can fix the problem with terminating the workflow after a particular step, not just the whole thing, not just discarding everything. And there is a halt on rescue handler, And it differs from discard on because it allows you to restart the job when the condition is fixed, because some errors are recoverable. There is also uniqueness built in. Just because we have a database of runs, we can easily achieve uniqueness. And let me show you how timers evolve. So previously, we had a scheduler and many jobs. Now we can have a single job with steps. And now steps have wait and wait until, and they describe the whole process. we have uniqueness here. And when we want to restart the lifecycle workflow for license, because it's been renewed, we just re-inqueue the job and it replace the previous workflow and continue working. All right. Yeah, that's another example with timers. And it has active record integration, has one performed, so you can easily access associated runs. And yeah, we're kind of a bit out of time. expected that so we just have a couple minutes left to show what's are the other features and I think the most favorite one so this is a previous temporal example with signals and when we convert it into durable continuation it becomes just this it's just a single file with a few configuration things and and that's basically it the whole logic lives in a single Rails Ruby class and you can observe it you can control it it's it's I don't know. It looks much better. And it looks something better than English, you mean. It's Ruby. It has structure and clear meaning. So, yeah, a couple of examples with signals. Yet again, generation example, but now an upgraded version when we decide whether the photo is good enough. If it's not, you know, it has a border score, we add human to the loop. and ask oh do you need does do you allow to post this image or not and now we do that by keeping a lot of states uh in the in on the model and just you know checking them and iterating in the job but there are problems with that because there could be concurrent executions we don't have history we don't have deadlines for the review with durable continuation we can change it with just single line it's a weight step it's just a special kind of step that parts the job For a given period of time, it could be released after the timeout. And then we can send a signal, say, from the controller or wherever we want to continue the execution. That's the whole API. And it works, yeah, on top of the same primitives as timers with just steps being empty bodies. So one bonus example. Recently, Ruby 11.0 was released, and it has a lot of examples. sample snippets with continuations involved. But they were not as good if they were using durable continuation, because now the whole loop could be implemented in a single job with restarting after approval, because we just have this halt method. And you can call resume whenever you approve or not the action. And that also simplifies this for a pro. We don't need durable state for real here, chat messages but still we need the control folder state to exist to implement it this way all right so that was a quick overview of the features we need to add to continuation to make it durable and more useful and drop all the stuff you using for that and it's available today like in a minute I gonna open source it's it's not yet available actually as a jam AG DC active job durable continuation nothing related to music. And yeah, it comes with everything I mentioned in the talk and more features coming. It comes with AI skills backed by Rails hyperdrive project. So all you need is to install Jam and tell your agents, oh, configure durable continuation, find job that would be nice to migrate and do the migration, and then that's it. Probably you'd like to read the code afterwards. I don't recommend not reading code. And the idea behind it is to bring just enough orchestration active job to stay on the rails way to not reach out for services or cryptic gems to implement these features we can do that in rails and we can you can see that it could be much better than using any of those so yeah more features coming I mentioned that that's a plan for you pick more they pay more attention to continuation try to see if you have this patterns in your code and they were workflows and give durable workflows a try. That's it. Thank you for your attention.