Library

Volume 1 · System Design Scenarios

Notebook
Sign in

Section 53

Microservices E-Commerce Platform Migration (Monolith to Microservices)

541 words · about 2 min

Problem Statement

A 15-year-old .NET Framework e-commerce monolith needs to move to microservices without a big-bang rewrite, while remaining in production throughout.

Migration Phases

Phase 1 — Prepare (Weeks 1-4): Map the monolith’s modules and their database table ownership. Add integration tests around critical paths (checkout, payment, inventory). Introduce an API Gateway (YARP/Ocelot/APIM) in front of the monolith so future service extraction is invisible to clients. Stand up shared infrastructure: message broker (Service Bus/Kafka), centralized logging, distributed tracing (OpenTelemetry).

Phase 2 — Extract first service (Weeks 5-8): Pick the least-coupled module with the clearest boundary — Notifications or Search are common starting points, never Payments or Orders first. Apply the Strangler Fig pattern: route /api/notifications/* at the gateway to the new service while everything else still hits the monolith. New service gets its own database from day one. Monolith publishes domain events; the new service subscribes — no synchronous coupling back into the monolith’s schema.

Phase 3 — Data separation (Weeks 9-12): Identify shared tables used by multiple modules (the classic monolith anti-pattern). Assign single ownership per table. Replace any cross-module direct SQL joins with API calls or event-driven materialized views. Accept eventual consistency where strict consistency isn’t actually required (e.g., “recently viewed” doesn’t need synchronous consistency with inventory).

Phase 4 — Iterate (ongoing): Extract one service at a time, highest business-value-per-effort first (Catalog, then Cart, then Inventory, then Orders, then Payments last — payments has the highest blast radius if done wrong). Each extraction: Test -> Extract -> Verify -> Cut Over. Track DORA metrics throughout (deployment frequency, lead time, change failure rate) to prove the migration is paying off, not just adding complexity.

Before:                          After:
+----------------------+        +---------+ +---------+ +----------+
|      Monolith         |        | Catalog | |  Cart   | | Payments |
| +------+ +---------+ |        | Service | | Service | | Service  |
| |Catalog| |Payments | |   ->    +----+----+ +----+----+ +----+-----+
| +------+ +---------+ |             |           |            |
| | Cart  | | Orders  | |        +----v-----------v------------v----+
| +------+ +---------+ |        |        Message Broker (Events)     |
|      Shared DB        |        +----+-----------+------------+----+
+----------------------+        +----v----+ +----v----+  +----v-----+
                                 | Orders  | |Inventory|  |Notification|
                                 | Service | | Service |  |  Service   |
                                 +---------+ +---------+  +------------+

Handling a Breaking Database Change Mid-Migration: Expand-Contract Pattern

  1. V1: Add new column (nullable), keep old column -> both app versions still function.
  2. Backfill: Background job migrates historical data old->new.
  3. V2: App writes to BOTH columns, reads from new -> safe to verify in production.
  4. Verify: Confirm data correctness, run reconciliation queries.
  5. V3: App only uses new column -> old column becomes dead code.
  6. Cleanup: Drop old column in a scheduled maintenance window.

Rule that never breaks: at every step, the previous app version must still work — this is what makes the deployment zero-downtime and instantly rollback-safe.

Avoiding a “Distributed Monolith”

Independent deployability (no coordinated releases), database-per-service (no cross-service SQL), backward-compatible API versioning, async-over-sync as the default (80% of inter-service traffic should be events, not blocking calls), and circuit breakers so Service A degrades gracefully rather than cascading when Service B is down. Red flags to watch for: all services must ship together, one service’s outage takes down everything else, and any shared database table across service boundaries.