Microservices patterns
Service boundaries, discovery, inter-service calls, and decomposition patterns.
How to Mock Eventual Consistency UI Notes in Python
Simulates a UI note that shows local state until a pending server update is confirmed, mocking eventual consistency behavior in distributed systems.
class EventualConsistencyNote:
def __init__(self, entity_id, note):
self.entity_id = entity_id
self.note = note
self.confirmed = False
self.pending_updates = []
def add_pending_update(self, update):
self.pending_updates.append(update)
def confirm_update(self):
…
How to Mock a Choreography Saga in Python
Simulate a choreography-based saga with event envelopes, status tracking, and compensating actions to model distributed transactions.
import json
from dataclasses import dataclass, asdict
from typing import List, Optional
from enum import Enum
class SagaStatus(Enum):
PENDING = "PENDING"
COMPLETING = "COMPLETING"
COMPLETED = "COMPLETED"
FAILED = "FAILED"
@dataclass
class EventEnvelope:
event_type: str
order_id: str
sta…
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.