Stackbook Logo
economics-evolutionestablished · high operational burden

Strangler Fig for APIs

Also known as: api-strangler, incremental-api-migration

Intent

Replace a legacy API gradually by routing endpoints one at a time to a new implementation behind a stable facade.

Problem

Rewriting a legacy API in one go is risky and delays value. Clients depend on its URLs and behaviour, so a big-bang cutover can break integrations with no easy rollback.

Forces

  • •Clients cannot all migrate at once
  • •Behaviour must stay compatible during migration
  • •Rollback must be quick
  • •Two systems must run side by side

Solution

Overview

Named after the fig that grows around a host tree, the strangler fig pattern grows a new API around an old one until the old one can be removed. Applied to APIs, the routing layer decides per endpoint which implementation answers.

How it works

A facade sits in front of both systems. Initially every route goes to legacy. Each migrated endpoint flips a rule.

client -> facade
  /v1/orders/*    -> new-orders-service   (migrated)
  /v1/invoices/*  -> legacy-api           (not yet)
  /v1/customers/* -> 10% new, 90% legacy  (canary)

A typical sequence: pick a low-risk, well-bounded endpoint; build it in the new system; run both and diff responses in shadow mode; route a small percentage; raise to 100 percent; remove the legacy code. Data ownership must be settled per slice, using either synchronisation, change data capture, or having the new service become the system of record.

Pitfalls

  • Migrating by technical layer instead of business capability, which leaves no usable slice.
  • Both systems writing the same tables. Decide a single writer per entity.
  • Forgetting the finish. Track remaining routes and set a decommission date.
  • Undocumented legacy behaviour. Shadow comparison reveals quirks clients rely on.
  • Treating the facade as free; it needs redundancy and monitoring.

Key takeaways

  • Route per endpoint, migrate in small reversible steps.
  • Verify with shadow traffic and canaries before cutover.
  • Settle data ownership for every slice.
  • Plan and measure the removal of the legacy system.
  • Measure it in production: track latency, error rates and volume for this pattern, and review the numbers regularly so that limits and timeouts stay matched to real traffic.

✓ When to Use

  • •Legacy API too large or risky to rewrite at once
  • •Clients depend on stable public URLs
  • •Need continuous delivery during migration

✗ When Not to Use

  • •Small API easily rewritten in a sprint
  • •Legacy system cannot be fronted by a proxy
  • •Data models are so entangled that endpoints cannot be separated

Pros

  • +Incremental risk and instant rollback
  • +Value delivered continuously
  • +Clients see no URL changes

Cons

  • −Two systems run in parallel for a long time
  • −Data sync between old and new is hard
  • −Facade adds a hop and a single point of failure

Cost Profile

Infrastructure

Medium - parallel runtime

Operational

High - long migration and dual maintenance

Cognitive

Medium - routing and data sync

Failure Modes

  • Migration stalls and the legacy system lives forever

  • Divergent behaviour between old and new endpoints

  • Shared database writes cause conflicting data

Real-World Examples

Alternatives

    Related Patterns

    • api-gateway

    Competency Domains

    economics evolutiondistribution communication