Announcing Hatchet v2 & our $5.7M seed round →
all posts ·

Your application now runs your compute

The vision behind sandboxes, durable streams, serverless runtimes, and operators in Hatchet v2.

Alexander BelangerAlexander BelangerCo-FounderHatchet

Startups tend to operate on a vision. Without a vision, you’re toast: milquetoast, not supertoast.

If you’ve been following along in the Hatchet ecosystem lately, you’ll have seen that in the past 2 weeks, we’ve launched integrations with sandbox providers, durable streams, integrations with serverless runtimes, a new runtime pattern called operators, and a new OSS project to self-host sandboxes called brickie.

This naturally begs the question: what’s the grand vision behind sandboxes, streams, serverless, and operators? That’s what I’d like to lay out in this post.

Your application now runs your compute

To start, an observation: we used to provision compute to run our applications. You’d build your application locally, bundle it up, rent a server on the cloud, and spawn your application on that server.

What we’re seeing now is very much an inversion of control: your application now runs your compute. Sandboxes are the clearest example of this. As part of your application logic, you pick an image, a compute size, and manage the lifecycle of a piece of compute from your application.

Compute used to contain the app. Now the app creates the compute.

But we’ve been trending towards this for a while. The design of serverless-friendly frameworks like Next.js is that it’s an application’s blueprint for splitting itself up and routing to individual functions, each running on their own little slice of compute. The thesis of newer stacks like convex.dev is making your application code and your infra one and the same.

For sandboxes, this paradigm is a necessity. For serverless, it’s a convenience. But both cases are an example of the modern app having more responsibility, becoming more fragmented, and becoming more scalable as a result.

There’s no free lunch

These types of shifts don’t happen without tradeoffs. As we like to say, “there’s no free lunch.” The result of a more distributed system is a host of distributed systems problems, like coordination, consistency, and accidental coupling. You risk building a house of cards, easy to knock over with the smallest breeze.

This is where orchestration emerges: it helps manage the complexity of systems becoming more distributed. Traditionally you’d have a separate orchestration system for different parts of your stack: you’d orchestrate your business logic (Temporal, task queues, message queues) separately from your data layer (Airflow, Dagster, Prefect) separately from your containers (Kubernetes, Nomad) from your sandboxes (agent SDKs).

But the phenomenon that I mentioned above (in agent systems and modern apps more broadly, your application manages your compute) is breaking down these boundaries. You can’t cleanly separate your orchestration systems. Your compute runs your application which runs your compute… and so on. We’ve seen this pattern recurse to 3 layers with some of our users, like running APIs which kick off agents running on Modal which kick off processes on specialized compute running in a self-managed datacenter (often someone’s basement).

So as we started iterating towards Hatchet v2, we started thinking about a central question: what if your orchestration system was universal?

The components of orchestration

Let’s be a little more precise.

I’d define orchestration as a system which manages and ensures the execution of complex workflows, each composed of multiple sub-processes.

Each sub-process represents a unit of work. Depending on the system that you’re dealing with, this unit of work could be a single function in an application, an entire lifecycle of a container or batch process, or an agent. An orchestrator will manage the lifecycle of each unit of work. This can mean executing to completion, termination when something goes wrong, etc.

In accomplishing this task, an orchestrator really has three functions:

  • Scheduling
  • Synchronization
  • Signaling

Scheduling

Scheduling is a method which figures out where, in a physical sense, the unit of work should run. For example, it could mean figuring out which VM to place a container, or scheduling a function/agent to run on a specific container. Schedulers are like load balancers: they distribute load between all resources available to the system.

A note on naming (the infamously hard problem): in application software, scheduling also has a different meaning, ensuring that work runs at a specific time in the future, like scheduling a cron job or one-time job. Orchestrators will frequently also bundle in a future scheduler to ensure that work is run at a certain time. Hatchet also supports future scheduling, but here we’re talking about scheduling units of work on processes.

Hatchet v0 and v1 support scheduling tasks on long-lived container processes called workers. It does a very good job at this. But Hatchet v2 expands the scheduling capabilities to include:

  • Sandboxes
  • Serverless runtimes
  • Any runtime you choose via the operator model

Synchronization

Orchestration systems also need to solve synchronization problems between different pieces of infrastructure. When applications get more distributed, state doesn’t just exist in one place. The earliest example of this is usually background jobs: your API handler updates a record in your database, and background jobs are used to bring the rest of your system or external systems into a consistent state with your application. Even sending an email to a user after signup is a form of state synchronization with onboarding.

You can’t solve synchronization without storing intermediate state somewhere. This was why Hatchet v0, v1 and v2 support durable execution or durable workflows: a useful way to handle intermediate state and eventual consistency without needing to build your own data layer.

In Hatchet v2, each workflow or task that you write has the ability to be durably executed, which means that you can guarantee that all of the different pieces of your application (a call into a sandbox, kicking off an agent, sending a notification to a user) are guaranteed to execute to completion.

Signaling

Lastly, orchestration systems build in a signaling mechanism. This is often internal, to accomplish scheduling and synchronization. But modern apps are usually operating with streams of information, and signaling is critical from the application perspective. For example, you might ingest a webhook which kicks off or resumes an agent, your agent might need to stream bits of information back to the user in the form of a message, or you might need agent-agent communication in the form of signals.

Because of these requirements, Hatchet v2 supports two primary ways to do signaling: durable streams and events. Streams are designed to be used for continuous streams of information, like streaming an LLM response to a user. Events are designed to be used as point-in-time wakeup or triggering mechanisms. Both are incredibly useful to the modern app.

Putting them all together

Let’s put all of these pieces together in the form of an example. Let’s say we have a code review agent which waits for an external event from Github, and kicks off a code review task in a sandbox. This is inherently a distributed and asynchronous system. Here’s how it would look in Hatchet v2:

import { HatchetClient } from "@hatchet-dev/typescript-sdk/v1";
import "@hatchet-dev/sandbox";
import type { PullRequestEvent } from "@octokit/webhooks-types";
import { review } from "./review";

const hatchet = HatchetClient.init();

export const reviewPr = hatchet.durableTask({
  name: "review-pr",
  onEvents: ["github:pull_request:opened"],
  fn: async ({ number, repository, pull_request }: PullRequestEvent) => {
    const topic = `review:${repository.full_name}:${number}`;
    const progress = (msg: string) => hatchet.streams.publish(topic, msg);

    const sandbox = await hatchet.sandbox.create({ provider: "e2b" });
    await sandbox.exec(`git clone ${repository.clone_url} . && git checkout ${pull_request.head.sha}`);
    const diff = await sandbox.exec(`git diff ${pull_request.base.sha}...HEAD`);

    // The agent loop: a model with one tool, which runs commands in the sandbox
    const result = await review(diff.stdout, async (cmd) => {
      await progress(`$ ${cmd}`);
      return (await sandbox.exec(cmd)).stdout;
    });

    await sandbox.kill();
    return { review: result };
  },
});

const worker = await hatchet.worker("review-worker", { workflows: [reviewPr] });
await worker.start();

Typically, this would have involved custom glue code with at least three different vendors (webhooks ingestion as a service, sandbox providers, and streaming). But in Hatchet v2, it’s written as a simple straight-line program with no side effects: as simple as writing an API handler.

The same pattern works with the agent frameworks Hatchet integrates with:

So that’s the grand vision. You or your coding agent can write incredibly simple programs which represent your core business logic, and Hatchet handles all of the underlying complexity of figuring out exactly how and where this all should run. And for platform teams, you can easily control the underlying orchestration layer, because it’s fully programmable via the operator model.