liveBook · Manning

Strangler fig pattern

As explained in Build High Value Software Systems

A gradual replacement pattern in which a new system is built alongside a legacy system and takes over its responsibilities incrementally.

Replacing a legacy system in one rewrite concentrates risk into a single large change. The strangler pattern builds new capabilities alongside the old system, then shifts responsibilities in small, reversible steps. section 7.3.2 section 7.6

A practical progression is to:

  • Add a routing layer that sends some requests to the new implementation and leaves the rest on the legacy system. section 7.3.2
  • Start with internal test traffic, verify behavior against the legacy system, then increase production traffic gradually. section 7.3.2
  • Replace one endpoint at a time; if defects appear, route requests back to the legacy implementation. section 7.3.2
Listing 7.9 Strangler Fig approach to isolate legacy payment capabilities
def process_payment(request):
    if should_use_new_system(request):
        return new_payment_service.process(request)
    else:
        return legacy_payment_system.process(request)
 
def should_use_new_system(request):
    # Phase 1: Internal test traffic only
    if request.headers.get('X-Internal-Test'):
        return True
 
    # Phase 2: 1% of production traffic
    if hash(request.user_id) % 100 == 0:
        return True
 
    # Phase 3: Gradually increase to 10%, 25%, 50%, 100%
    return rollout_percentage_for_user(request.user_id) < CURRENT_ROLLOUT_PCT

The payment example shows request routing from internal tests to percentage-based production rollout. section 7.3.2

How Build High Value Software Systems covers it

How deep it goes
Details request routing, staged traffic shifts, behavior checks, endpoint-by-endpoint replacement, and rollback.
Examples
Uses a payment API, replacing `/payments/create` while `/payments/refund` remains legacy, with internal and percentage-based traffic.
What you can do after
Apply the pattern by routing selected requests to a new service, checking behavior, then increasing rollout or routing back.
How it connects
Connects to feature flags, routing layers, legacy systems, and behavior validation.

Also explained in

Compare how 6 books explain strangler fig pattern →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build High Value Software Systems. The section links point to the parts of the book it draws on.