This demo environment showcases Circuit Breaker behavior implemented with Django and Django REST framework (DRF), running under the Daphne ASGI webserver. The system includes three services (frontier, midline, backline) that call one another to simulate successful and timeout scenarios and observe application‑level Circuit Breaker reactions.
- Django + DRF: Build APIs via
rest_framework.views.APIView
. - Daphne: ASGI webserver, entrypoint
CircuitBreaker.asgi:application
. - Nginx: Reverse proxy to the
frontier
service (host port 8001). - Docker/Compose: Packaging and running multiple services.
- Build/run script:
./dockerc.sh
- Builds the image
circuit-breaker:latest
fromdocker/Dockerfile
. - Starts services via
docker/docker-compose.yaml
(frontier, midline, backline, nginx).
- Builds the image
Execute:
./dockerc.sh
Once running, access via Nginx at: http://localhost:8001/
Routes are mounted per app. Quick reference:
- Frontier (public via Nginx, port 8001):
GET /api/success-request
GET /api/timeout-request
- Midline and Backline (internal in the compose network) expose the same routes to form a call chain.
Disable Circuit Breaker per request via query param:
?non_circuit_breaker=1
Examples:
curl "http://localhost:8001/api/success-request"
curl "http://localhost:8001/api/timeout-request"
curl "http://localhost:8001/api/timeout-request?non_circuit_breaker=1"
- OpenAPI schema:
GET /api/schema/
- Swagger UI:
GET /api/schema/swagger-ui/
Via Nginx (host):
http://localhost:8001/api/schema/
http://localhost:8001/api/schema/swagger-ui/
- ASGI:
src/CircuitBreaker/asgi.py
and Daphne entrypoint indocker/entrypoint.sh
. - Base DRF view:
src/apps/sharedapp/apis/proxyrequest.py
(handlesnon_circuit_breaker
, returns 503 when circuit is open, 502 for transient errors). - Compose:
docker/docker-compose.yaml
(defines the 3 services and Nginx proxy on port 8001). - Nginx config:
configs/nginx.conf
(upstream tofrontier:8000
).
- On first start, the container runs
migrate
andcollectstatic
automatically (seedocker/entrypoint.sh
). - Environment variables that link service calls are set in compose (e.g.,
FRONTIER_DOMAIN
,MIDLINE_DOMAIN
,BACKLINE_DOMAIN
).
- Goal: Run the same services on a local Kind cluster with Istio and apply network‑level circuit breaking to
backline
usingDestinationRule
andVirtualService
.
Prerequisites
docker
,kind
,kubectl
,istioctl
available in PATH.
Build image and initialize cluster
- Build the Docker image locally:
./dockerc.sh
- Create Kind cluster, install Istio, deploy manifests, and apply CB policies:
./k8sinitialrc.sh
Expose Istio Ingress (Kind)
- Port‑forward the Istio ingressgateway to host port 8002:
kubectl -n istio-system port-forward svc/istio-ingressgateway 8002:80
- Access Frontier via Istio at:
http://localhost:8002/
Apply updates after code changes
- Re‑apply manifests and reload the image into Kind:
./k8sreloadrc.sh
Istio CB config in this repo
docker/k8s/circuit-breaker.yaml
defines:DestinationRule
forbackline
with connection pool limits and outlier detection.VirtualService
forbackline
withtimeout
andretries
.
- Traffic flow:
frontier -> (midline) -> backline
via cluster DNS. The CB applies to calls targetingbackline.circuit-breaker.svc.cluster.local
.
Load testing
- Use the provided script to send requests and observe HTTP codes/latency:
- For Docker Compose (Nginx, port 8001), default in
curlspam.sh
is already set. - For Istio/Kind (port 8002), edit
curlspam.sh
to use:URL="http://localhost:8002/api/timeout-request?non_circuit_breaker=true"
- For Docker Compose (Nginx, port 8001), default in
./curlspam.sh
- You can also run one‑offs:
curl -i http://localhost:8002/api/timeout-request
curl -i "http://localhost:8002/api/timeout-request?non_circuit_breaker=true"
- Requires Python 3.13 if running outside Docker.
- Install dependencies from
src/requirements.txt
and runpython src/manage.py runserver
, or start Daphne manually.