Reference library

Microservices patterns

Service boundaries, discovery, inter-service calls, and decomposition patterns.

2 matches
Microservices patterns easy

How to Use the Adapter Pattern to Mock a Legacy System in Python

This code demonstrates the Adapter pattern, allowing a modern interface to interact with a legacy system by wrapping its outdated method.

adapter-pattern design-patterns legacy
Python
class LegacySystem:
    def legacy_method(self, data):
        return f"Legacy processed: {data}"

class ModernInterface:
    def process(self, data):
        raise NotImplementedError

class Adapter(ModernInterface):
    def __init__(self, legacy):
        self.legacy = legacy

    def process(self, data):
        re…
13 0 Open
Microservices patterns easy

Strangler Fig Migration Pattern in Python

Gradually reroute calls from a legacy service to a modern replacement using a runtime switch and feature detection.

migration facade microservices
Python
from dataclasses import dataclass

@dataclass
class PaymentService:
    def process(self, amount: float) -> str:
        return f"Legacy processed ${amount:.2f}"

class StranglerFig:
    def __init__(self):
        self._new_service = None

    def attach_new(self, service):
        self._new_service = service

    de…
14 0 Open

Browse by section

Each section groups closely related Python snippets.

Microservices patterns — Python code examples

What you will find here

This page collects microservices patterns snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.