Spot the flaws: moving an order platform to events
A design review exercise. Eight flaws are planted below. Read the whole document, note your concerns, then reveal the answers at the end.
Design: Orders service and migration
Section titled “Design: Orders service and migration”Author: Commerce platform team · Status: Ready for architecture review · Reviewers: you
1. Context
Section titled “1. Context”Orders, inventory and pricing live in one monolith and one database. Black Friday traffic of about 4,000 orders a minute saturates the database every year. We’ll move orders into their own service with its own database, communicate through events, and migrate 60 million historical orders without downtime.
2. Goals
Section titled “2. Goals”- Order placement survives a 3× Black Friday peak.
- No orders lost or duplicated during the migration.
- A rollback path at every stage.
- Product pages stay fast: prices served from a cache.
3. Architecture
Section titled “3. Architecture”4. Key decisions
Section titled “4. Key decisions”4.1 Fulfillment as a saga. Placing an order runs a saga: reserve stock, take payment, create shipment. If a step fails, earlier steps are compensated. To compensate the stock reservation, the worker records the product’s available quantity before reserving and writes it back.
4.2 Workers and scaling. Saga workers are autoscaled on queue depth, from 10 to 80 instances, each with a pool of 20 database connections to the monolith’s database.
4.3 Price cache. Product pages read prices through a cache-aside layer. When a price changes, the pricing code commits the new price, then deletes the cache entry. Entries expire after 24 hours as a safety net.
4.4 Health checks. Each service exposes /health, which checks its database connection and returns 200 only if the database responds within 1 second. Kubernetes uses /health as both the liveness and the readiness probe.
5. Migration
Section titled “5. Migration”5.1 Data. A change-data-capture stream copies changes from the monolith’s order tables to the new database as they happen. At the same time, a backfill job copies the 60 million existing orders in batches of 50,000. Both write to the new database with upserts, so whichever runs second simply brings the row up to date.
5.2 Verification. Before switching, we shadow production traffic to the new service for two weeks and compare responses. The comparison waits up to 2 seconds for both responses and reports the share of compared pairs that match. We need 99.9% agreement.
5.3 Reconciliation. We confirm that both databases have the same number of orders and the same total order value for each day.
5.4 Cutover and rollback. Cutover switches the storefront’s routing to the new service. If anything goes wrong, we switch the routing back; the monolith is untouched and ready to resume.
6. Release safety
Section titled “6. Release safety”New versions of the orders service go to a 5% canary for an hour and are promoted automatically if the canary’s error rate is below 0.1%.
7. Observability
Section titled “7. Observability”Each service emits traces with OpenTelemetry, and the order journey (placed, paid, shipped) has its own dashboard.
Reveal the flaws
Section titled “Reveal the flaws”Try to find all eight before opening these.
Flaw 1, in section 4.1
Compensation writes back a remembered quantity. If another order reserved stock in between, writing back the earlier quantity erases that reservation, and stock is sold twice. Running the compensation twice repeats the damage.
Ask for: reservations recorded by ID, so compensation releases only its own reservation and is safe to repeat.
Learn it: The compensation that undid somebody else’s work · Check C-20
Flaw 2, in section 4.2
At 80 workers × 20 connections, the workers ask for 1,600 connections to a database the whole migration exists to relieve. On Black Friday, a backed-up queue scales workers up, more workers hit the saturated database, completions fall and the queue grows faster.
Ask for: a limit on concurrent work against the monolith that’s shared by all workers, scaling on the age of the oldest job only when the downstream has headroom, and a retry budget.
Learn it: The autoscaler that made the backlog worse · Rule that breaks: “Autoscaling handles traffic spikes”
Flaw 3, in section 4.3
Delete-after-commit with a 24-hour expiry can serve an old price for a day. A reader that loaded the old price before the change and writes it to the cache after the delete puts the old price back, and nothing removes it until it expires. With thousands of price changes, this happens regularly.
Ask for: versioned cache fills, or leases, so a fill older than the last invalidation is rejected; and a much shorter expiry for prices.
Learn it: The cache that went stale right after invalidation · Check C-19
Flaw 4, in section 4.4
The liveness probe checks the database. When the database is slow, which is the Black Friday problem, every pod fails liveness and Kubernetes restarts them all at once. Restarts don’t fix a slow database; they remove the capacity that was still working and add a reconnection surge.
Ask for: liveness that checks only whether the process itself is stuck; readiness that reflects whether the pod can serve; and dependency problems handled by readiness and load shedding, not restarts.
Learn it: The self-healing restart that prevented recovery · Incidents by mechanism: health checks remove healthy capacity
Flaw 5, in section 5.1
Unconditional upserts from two writers mean the last writer wins, not the newest data. A backfill batch that read an order before a customer changed it, and writes after the change-data stream delivered the change, overwrites the newer version. “Whichever runs second brings the row up to date” is true only if the second writer has newer data.
Ask for: every write carrying its source revision or log position, and writes that apply only when newer.
Learn it: The backfill that overwrote a live update · Check C-13
Flaw 6, in section 5.2
Agreement is measured only over pairs that completed within 2 seconds. The requests the new service handles worst, such as large orders, time out and drop out of the comparison. The report can show 100% agreement while the riskiest requests fail.
Ask for: every eligible request accounted for, including candidate timeouts and errors, with a coverage threshold as well as an agreement threshold.
Learn it: The shadow test that missed the dangerous requests · Check C-16
Flaw 7, in section 5.3
Counts and totals can’t prove a migration correct. Swapped values, a missing order offset by a duplicate, or a wrong customer on an order all leave counts and totals unchanged.
Ask for: a keyed comparison of every order and the fields that matter, with hash comparison by key range to make 60 million rows practical.
Learn it: The migration that passed reconciliation, with a lab · Check C-15
Flaw 8, in section 5.4
Rollback switches routing but forgets data. Orders placed on the new service after cutover don’t exist in the monolith. Switching back loses every one of them, which contradicts goal 2.
Ask for: post-cutover writes replicated back to the monolith until a declared point of no return, a rollback that verifies they arrived, and a rehearsal that places orders before rolling back.
Learn it: The rollback that lost successful orders · Check C-14
Looks wrong, but is fine, or nearly
- Section 3, leaving inventory and pricing in the monolith for now. A sensible strangler step: move one bounded context at a time.
- Section 7, a dashboard for the order journey. Good, and better than endpoint dashboards alone.
- Section 6, a 5% canary with automatic promotion. Reasonable in principle. A strong reviewer would add one question: is the 0.1% gate global, or checked per cohort, such as large orders or particular payment methods? A global gate can pass while one cohort fails completely (the green canary that failed a small tenant). Credit yourself if you asked it.
Score yourself
Section titled “Score yourself”| Found | What it suggests |
|---|---|
| 7 or 8 | You’d catch these before Black Friday rather than during it. |
| 4 to 6 | Solid. Migrations hide flaws in the steps that only run once. |
| 3 or fewer | Read the migration and concurrency stories, then try again. |
Written and edited by Abhinav Taduka, enterprise software architect.
New pages are added regularly. Follow Abhinav on LinkedIn to see them first.