Microservices patterns
Service boundaries, discovery, inter-service calls, and decomposition patterns.
How to mock a SPIFFE workload identity in Python
Generate a mock SPIFFE ID and token for a workload using a trust domain, namespace, and service account.
import hashlib
import json
from dataclasses import dataclass, asdict
@dataclass
class SPIFFEIdentity:
trust_domain: str
namespace: str
service_account: str
@property
def id(self) -> str:
return f"spiffe://{self.trust_domain}/ns/{self.namespace}/sa/{self.service_account}"
def mock_workl…
Zero Trust Service Auth Mock in Python
A simple HMAC-based token issuance and validation mock that enforces zero trust between microservices.
import hmac
import hashlib
import json
import time
class ZeroTrustAuth:
def __init__(self, secret_key):
self.secret_key = secret_key
self.service_tokens = {}
def issue_token(self, service_name, ttl=300):
payload = {
"service": service_name,
"issued_at": int(tim…
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.