Skip to content

M2: resilience and independence — Circuit Breaker, Stateless Services, Contract Testing, Service Discovery - #3

Merged
MAOFILHO merged 1 commit into
mainfrom
m2/resilience
Nov 15, 2026
Merged

MAOFILHO merged 1 commit into
mainfrom
m2/resilience

Conversation

@MAOFILHO

Copy link
Copy Markdown
Owner

Milestone M2 of docs/PLAN.md. 8 of 12 patterns are now live.

Patterns

  • 4 Circuit Breaker: order → payment goes through pybreaker (opens after 3 failures, retries after 15 s) plus tenacity (1 retry, 1 s timeout). Checkout now prices the cart from catalog and charges payment. When payment is down, checkout returns a clear 503 and keeps the cart. The demo has a healthy / failing / slow switch: a real failure takes 2,215 ms, and a call stopped by the open breaker takes 0 ms.
  • 10 Stateless Services: login returns an RS256 token signed by the user service. The gateway (at the edge) and order check it with the public key. Flask-Login and stored API keys are removed. Order runs as 2 local replicas, and stopping one keeps you logged in with the same cart.
  • 11 Contract Testing: order's tests write Pact contracts (contracts/pacts/). Payment and catalog check them against the real service in their CI suites. Renaming amount_cents in payment fails CI.
  • 12 Service Discovery: a new registry/ service on port 8500 (heartbeat 2 s, TTL 10 s). Callers round-robin across live instances, and the gateway retries on the next replica when one refuses the connection. Azure keeps using Container Apps DNS.

Tests

  • 65 unit tests across 8 suites (registry is new), including the breaker opening, token tampering, and replica failover.
  • 19 smoke tests passed and 3 skipped (Azure only), including: both replicas serve the same cart, a bad token is rejected at the gateway, and the breaker opens and then closes.
  • Browser click-through of all 4 pages. Screenshots are in docs/screenshots/p04, p10, p11 and p12.

Notes

  • Sign-ins saved before this change hold an old API key. The Shop page treats them as signed out.
  • CHAOS_ENABLED=1 (set by make run) is required for the stop and break switches. It is off by default.
  • Nothing is deployed to Azure.

🤖 Generated with Claude Code

…vice Discovery live

- Pattern 10: the user service signs RS256 login tokens; gateway and order verify them with
  its public key. Flask-Login and stored API keys removed. Order runs as 2 local replicas.
- Pattern 12: a small FastAPI registry (heartbeat 2 s, TTL 10 s). Services register, callers
  round-robin across live instances, and the gateway fails over on a refused connection.
- Pattern 4: order -> payment through pybreaker (3 failures, 15 s) + tenacity (1 retry).
  Checkout now prices from catalog and charges payment; the cart is kept when payment is down.
- Pattern 11: Pact contracts from order to payment and catalog, verified in their CI suites.
- 4 new demo pages with screenshots, make run restarts stopped services, CI adds the registry
  suite and Pact, Bicep passes catalog and payment URLs to order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MAOFILHO
MAOFILHO merged commit 4a0fc16 into main Nov 15, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant