Video in progress

How do you design a business process that lasts for days (for example, a loan application: checks, human approval, deadlines) across microservices?

I store the process state as a durable workflow: every step, wait and timer is recorded in the DB or in a workflow engine (Temporal, Camunda). Human approval is an external signal, deadlines are durable timers, and the steps are idempotent activities.

📖 Answer

You can't build such a process with a single HTTP request or an in-memory CompletableFuture: services get deployed, pods die, and the process has to wait 5 days.

A loan application flow looks roughly like this:

SUBMITTED -> scoring (automatic, minutes)
          -> document check (external API, hours)
          -> manager approval (human, up to 3 days)
          -> no answer in 3 days -> escalation
          -> APPROVED -> open account, contract, transfer money

What I pay attention to:

Durable state. Every transition is in the DB (your own state machine) or in the engine's event history. If a service restarts, the process continues from the same place.

Timers. "Escalation after 3 days" is not a Thread.sleep and not an in-memory scheduler either. A due_at column in the DB and a job that checks it, or Workflow.sleep(Duration.ofDays(3)) in Temporal, which is stored in the engine and works even when the workers change.

The human step. When the manager clicks "approve" in the UI, a signal is sent to the workflow. The signal must be idempotent (if clicked twice, one approval).

Idempotent steps. Every external call is ready for retries: opening an account with an idempotency key by applicationId.

Versioning. The most overlooked point: during a 5-day process the flow code can change. Which version do applications that are halfway through continue on? In Temporal it's Workflow.getVersion, and in your own state machine it's the rule of only adding states and transitions (never removing).

Visibility. The business asks "where is the application stuck". You need a history screen for every application and a metric for how long each step takes.

An engine like Temporal gives you much of this, but adopting it is a platform decision. For one or two processes, a well-written table + outbox + scheduler will also be enough.