← Back to blog

Dev notes / 02

Don't keep job state in memory

A deploy will restart your process at the worst moment. Store job status somewhere that survives it.

Diagram for Don't keep job state in memory
Diagram · Don't keep job state in memory

Here’s a pattern we see a lot: an in-memory Map<jobId, status>, a background task that updates it, and an endpoint that reads it. Fine until the first deploy. The process restarts, the map is empty, and every client polling for a result gets a 404 for a job that existed thirty seconds ago.

💥 What actually breaks

Losing the status is the small part. The bigger problem is that nobody knows what happened to the work:

  • Did the job finish before the restart, or did it die halfway?
  • Is it safe to run it again, or will it charge a card twice?
  • What do you tell the user who’s staring at a spinner?

With nothing written down, every answer is a guess.

💾 Write the status where it outlives the process

Store each job as a row (or document, whatever you already use) with a status field and timestamps. Update it on every transition. Your workers can crash and come back, and the record still says where each job was.

A minimal shape to start with:

{
"id": "exec_01H...",
"status": "running",
"created_at": "2026-10-27T09:12:03Z",
"updated_at": "2026-10-27T09:12:05Z"
}

You don’t need to store every log line here. Store whatever you’d need to decide what to do after a crash.

🔁 Plan the retry before you need it

When a worker vanishes mid-job, decide in advance: retry automatically, mark it failed, or flag it for a human? Each one is reasonable for different workloads, but pick one before the 3 a.m. page instead of during it.

🧪 Trying it with mPaka

The mPaka API gives every execution a record you can fetch with GET /v1/executions/{id}, so a restart on our side doesn’t wipe your view of it. Locally the executor is mock_no_code_execution, which means the statuses are real but no submitted code actually runs.