At a glance
The useful line on an architecture diagram is the one that explains what survives failure together. Follow an export request through quota, durable work and rendering, and the choice between a worker and a service becomes a decision you can test.
- Draw the writes that must commit together before drawing independently deployable services.
- Separate expensive computation from HTTP without assuming it needs independent data ownership.
- Make extraction earn its cost through measured pressure, explicit recovery states and an accountable owner.
Find the promise hiding inside the boxes
Architecture is strangely seductive when everything is still a rectangle. Every responsibility has a name. Every arrow arrives. I find the drawing becomes more useful when I interrupt it: the process dies here; what has the customer now been promised?
Take an analytics product. A customer requests a CSV export of an immutable dataset snapshot. Each accepted export consumes one allowance credit. Rendering can be expensive, but acceptance should stay fast. A retry after a lost response must recover the same job, without consuming another credit. The workload and credit model in this article are design fixtures, not measured customer data.
There are already three boundaries: the code responsible for export rules, the process doing the computation, and the data that must change atomically. They can be different shapes. Start with the invariant: one accepted request means one job, one credit debit and one recoverable dispatch intent. A rejected request changes none of them. Now the drawing has something to defend.
Keep acceptance inside one short transaction
Two processes. One owner of the acceptance promise.
↔ Scroll across diagrams and tables to inspect the detail.
Read the ownership and dependency contract
| Boundary | Contract |
|---|---|
| HTTP → Exports | Authenticated tenant and authorized snapshot; stable request key. Receipt returned only after job, quota, request and outbox commit. |
| Exports → database | Exports alone changes these tables. Accounts supplies identity through an interface; it cannot edit export quota directly. |
| Relay → worker | Duplicate job IDs are expected. A claim generation fences completion; no long transaction encloses the rendering work. |
| Worker → artifact store | Write an immutable attempt object, then publish its pointer only if the claim generation remains current. Clean up orphan objects later. |
| Future service boundary | Keep export allowance with admission, or explicitly design reservation, cancellation and reconciliation across owners. |
Inspect nodeClaim request identity⌄
A unique tenant, operation and request key identifies the intent. Record a fingerprint of the normalized input so an accepted duplicate can recover its original receipt.
Let an Exports module own the request ledger, export allowance, jobs and outbox. Accounts owns identity; it does not update export tables. The HTTP adapter authenticates the caller, checks access to the selected snapshot and calls the module. In-process interfaces control dependencies even though the modules share a deployment.
The admission command claims a unique tuple (tenant, operation, request_key), compares a normalized payload fingerprint on duplicates, conditionally debits allowance and inserts the job plus outbox row. All of those writes commit together. An outbox stores the intention to dispatch in the same database transaction as the business change; its relay can publish again after a crash, so consumers must handle duplicates. This is the failure addressed by the transactional outbox pattern.
Do not read a balance, decide in application code and later write the new number. Make availability part of the write and require one affected row:
UPDATE export_quota
SET remaining = remaining - 1
WHERE tenant_id = :tenant AND remaining > 0
RETURNING remaining;
This fragment sits inside the admission transaction after winning the request identity. Zero returned rows means rollback. At PostgreSQL Read Committed, a concurrent update waits for the row and rechecks its condition against the updated version. That supports this single-row guard; it does not make arbitrary multi-row invariants safe. See PostgreSQL transaction isolation. The companion retry field guide follows the complete failure path.
Give rendering its own process before giving it its own service
A worker can use the same Exports code and schema while running with separate CPU limits and replica counts. That already removes rendering from the HTTP process. It remains coupled to compatible application and database releases. Calling it a microservice would conceal the independence it does not yet possess.
The job envelope contains a job ID and input version. The worker loads the authoritative job, takes a bounded lease with a new claim generation, and renders outside a database transaction. It writes an immutable artifact under a path such as tenant/job/generation.csv. Completion updates the job’s artifact pointer only if that generation still owns the claim. An expired worker may finish computation; it cannot publish over the current result. Unreferenced artifacts need later cleanup.
This design deliberately tolerates repeated computation. It protects one visible completion. If rendering calls a provider that charges per request, the lease alone does not prevent duplicate charges: the provider needs its own stable idempotency key or an explicit reconciliation path. Keep that limitation on the diagram.
A database-backed job queue can also be a reasonable first design; then the durable jobs table replaces the broker dispatch path. The outbox is useful here because the worked example uses an external broker. It should not become infrastructure you add without a dependency to cross.
Price the new failure states
Which freedom would you actually buy?
↔ Scroll across diagrams and tables to inspect the detail.
| Observed pressure | Smallest useful change | Evidence that would justify more | New bill to pay |
|---|---|---|---|
| Renders starve HTTP CPU | Separate worker process; cap parallel renders. | Compare request latency under the same render load before and after isolation. | Worker supervision, leases, retries. Shared database remains a failure domain. |
| Worker queries saturate the database | Bound query cost and admission; inspect locks and query plans. | Residual database contention after those changes; a stable data subset with a clear owner. | Moving a process alone buys no database isolation. |
| Independent team cannot release a renderer safely | Define a versioned job envelope and compatibility window. | Release history shows coordination is the constraint; team accepts full service operations. | Contract tests, dual-version support, migrations, on-call ownership. |
| Quota and job must commit together | Keep their write ownership together. | A business rule permits reserved / pending states and recoverable partial outcomes. | Reservation expiry, reconciliation, stuck-state visibility; more ways to fail. |
Inspect nodeWhat is blocked?⌄
Distinguish HTTP CPU, database contention, release coordination and the need for atomic admission. The same service split would affect each pressure differently.
Suppose someone proposes moving allowance into an Account service. The acceptance operation now crosses two owners. A debit can succeed while creating the export fails; a timeout can leave its outcome unknown. You need to co-locate that allowance with admission, or introduce a reservation protocol: reserve with a stable identity, admit against it, confirm or cancel, and reconcile reservations that remain unresolved. That is a change to product states as well as infrastructure.
Microsoft’s microservices architecture guidance calls out data consistency, communication and versioning as consequences of independent services. In this example those consequences become concrete: who may cancel a reservation, whether a pending export is visible, and which owner repairs a stranded credit.
Measure before pricing capacity. For an arrival rate of 6 exports per minute and 8 CPU-seconds per export, average rendering demand is 6 × 8 / 60 = 0.8 CPU cores. That is offered CPU load, not a capacity recommendation: bursts, memory, I/O and completion deadlines still matter. Capture their distributions in a representative workload test. A separate worker can address CPU pressure while leaving database lock contention unchanged.
Put a number on the split. Availability multiplies across a network boundary. If admission needs two services and each is available 99.9% of the time, admission is available 99.8% of the time at best. In a 30-day month that is about 86 minutes of failed admissions against 43.
The split can still be the right choice. It must buy something worth those 43 minutes: a different scaling curve, a separate release rhythm or another owner. Name that purchase in the decision record.
Write the decision another engineer can reopen
An ADR preserves why a choice made sense when it was made. The structure below adapts Michael Nygard’s architecture decision record to this example. Every field is filled in; the status is a proposed design, not a claim about an existing deployment.
ADR: Keep export admission atomic; isolate rendering
Status: Proposed for the analytics product
Owner: Product engineering team, including worker operations
Context
- One team owns HTTP, rendering and export allowance.
- Acceptance must create one job and debit one credit together.
- Rendering must not consume HTTP process capacity.
- Independent release ownership has not been demonstrated.
Decision
- Exports owns requests, quota, jobs and outbox in PostgreSQL.
- Run HTTP and workers separately from compatible code versions.
- Deliver job IDs through an outbox relay and broker.
- Fence completion by claim generation; publish immutable artifacts.
Alternatives
- Inline rendering: rejected; ties request capacity to job duration.
- Independent Export service: defer; no independent owner yet.
- Database job queue: credible simpler option if broker is unnecessary.
Consequences
+ Atomic admission; workers scale without HTTP replicas.
- Shared database and schema release remain common failure domains.
- Team owns relay lag, leases, duplicate delivery and orphan cleanup.
- External paid effects still require a separate retry contract.
Validation before adoption
- Lose the acceptance response: same receipt, one credit debit.
- Restart relay after publish: duplicate event cannot republish a job.
- Expire a worker claim: late completion cannot replace new output.
- Replay representative load: measure HTTP latency and queue age.
Reopen when
- A stable renderer owner needs independent release timing, and
release records show shared coordination is a material delay; or
- Measured database/resource isolation needs survive query tuning,
concurrency limits and separate worker capacity.
Extraction prerequisites
- Versioned envelope; compatibility and migration plan.
- Owned data and explicit cross-boundary recovery states.
- Named operator, dashboards and rehearsed rollback/reconciliation.
Take your busiest or most failure-sensitive command and write its equivalent of the acceptance invariant. Circle the rows it changes. Then draw the process boundary that removes the actual bottleneck. You may still choose services. You will know what the boundary buys, what it breaks and how to tell when it is time to move it.