Reference library

System design patterns

Sharding, load balancing, CAP tradeoffs, and scaling patterns — interview and production ready.

2 matches
System design patterns easy

How to Implement a Simple Event Bus in Python

Create a publish-subscribe event bus using dataclasses and defaultdict to decouple event producers from consumers.

event-bus publish-subscribe design-patterns
Python
from collections import defaultdict
from dataclasses import dataclass, field
from typing import Callable, Dict, List, Set


@dataclass
class EventBus:
    _subscribers: Dict[str, List[Callable]] = field(
        default_factory=lambda: defaultdict(list)
    )

    def subscribe(self, event_type: str, handler: Callable…
15 0 Open
System design patterns easy

Idempotent Consumer: Store Processed IDs in Python

Implement an idempotent consumer that persists processed message IDs to a JSON file, skipping duplicates on restart.

idempotency duplicate-detection state-persistence
Python
import json
from pathlib import Path


class IdempotentStore:
    def __init__(self, storage_path: str = "processed_ids.json"):
        self.storage_path = Path(storage_path)
        self.processed_ids = self._load()

    def _load(self) -> set:
        if self.storage_path.exists():
            with self.storage_path…
15 0 Open

Browse by section

Each section groups closely related Python snippets.

System design patterns — Python code examples

What you will find here

This page collects system design 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.