Repository navigation
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat(observability): Add OpenTelemetry tracing for traffic decisions and lease operations #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
feat(observability): Add OpenTelemetry tracing for traffic decisions and lease operations #16
Changes from all commits
9ebbe75cc24a293c4164cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
⚡ Distributed Traffic Control
Globally coordinated traffic control for distributed systems
A production-oriented traffic-control platform built with Java 21 and Spring Boot, using Redis-backed leases, atomic coordination, and bounded capacity allocation to enforce shared global limits across multiple application instances.
Overview · Architecture · Coordination · Quick Start · Performance · Observability · AWS · Production Readiness
🎯 Overview
Distributed traffic control is straightforward on one process and much harder once the same capacity must be shared by several independent application instances.
A naive per-node limiter can accidentally multiply a global limit:
This project separates the problem into two layers:
The result is a distributed traffic-control engine where multiple gateways can make local decisions while still respecting a single global capacity boundary.
Why this project exists
The interesting engineering problem is not implementing a basic rate limiter. It is handling the distributed-systems concerns around it:
✨ Highlights
🏗️ Architecture
flowchart TB R[Traffic Request] --> E[Traffic Decision Engine] E --> P[Policy Resolver] E --> Q[Local Quota Enforcement] Q -->|Quota available| A[ALLOWED] Q -->|Quota exhausted| C[Capacity Allocator] C --> L[Redis Lease Coordinator] L --> G[(Redis Global Capacity)] L --> H[(Lease Registry)] G --> L H --> L L --> C C -->|Lease acquired| A C -->|No global capacity| D[REJECTED]Request decision flow
Local vs. global state
policy + subject + resourcepolicy + resourceleaseIdpolicy + resourceThis separation keeps Redis off the normal local-capacity path while preserving a single globally coordinated capacity boundary when nodes need more quota.
🧠 Core Design
Traffic subject
A
TrafficSubjectidentifies the entity generating traffic.Supported subject types:
Traffic policy
A
TrafficPolicydefines how traffic is controlled.Supported policy types:
Policies also carry lifecycle state and capacity/refill configuration.
Local quota
The local quota identity is:
The gateway can therefore make many decisions without contacting Redis.
Global capacity
The distributed capacity identity is:
All gateway instances coordinate against the same shared pool.
Quota lease
A
QuotaLeasetemporarily assigns a bounded portion of the global pool to a gateway.The default deployment caps an individual lease at 10 units.
🔐 Distributed Coordination
Redis state is conceptually organized as:
Why Redis Lua scripts are used
Several distributed operations update multiple pieces of Redis state together. Performing those mutations as independent commands would introduce race windows.
The coordinator therefore uses Lua scripts for operations such as:
This makes the state transition atomic from Redis's point of view.
Lease acquisition
Conceptually:
Expiration and reclamation
Redis key expiration alone is not sufficient when unused lease capacity must be returned to the global pool.
The implementation keeps an explicit lease registry:
This prevents abandoned reservations from permanently reducing the shared capacity pool.
♻️ Lease Lifecycle
A lease is therefore a stateful distributed resource with explicit ownership and lifecycle semantics, not just an integer counter.
🛠️ Technology Stack
🌐 API
Evaluate traffic
Example request:
{ "requestId": "req-001", "subject": { "subjectId": "user-123", "type": "USER" }, "resource": "/api/orders", "requestedAt": "2026-09-07T15:20:00Z" }Example response:
{ "status": "ALLOWED", "reason": "Request allowed", "remainingCapacity": 99 }Possible decision status values include:
Traffic admission is intentionally separate from HTTP transport semantics: a request can receive a valid HTTP response while the traffic-control decision itself is
REJECTED.🚀 Quick Start
Prerequisites
Install:
Clone
git clone https://github.com/yashdotdev13/distributed-traffic-control.git cd distributed-traffic-controlRun the test suite
Linux/macOS:
Windows PowerShell:
Start the distributed local environment
Check the services:
Health checks
Expected health state:
{ "status": "UP" }Stop the environment
⚙️ Configuration
The application uses environment-driven configuration.
For distributed deployment, each gateway receives a unique
NODE_IDwhile all gateways share the same Redis-backed global capacity pool.📊 Observability
Prometheus metrics are exposed at:
Key application metrics:
Metrics intentionally avoid high-cardinality identifiers such as request IDs and subject IDs.
Operational signals
The metric model is designed to make the following behaviors observable:
Prometheus scrapes the gateway instances and Grafana provides the dashboard layer.
Distributed tracing with OpenTelemetry
The application uses Spring Boot's Micrometer Observation/OpenTelemetry integration to export distributed traces over OTLP, with Jaeger providing the local trace visualization interface.
The instrumentation covers the traffic-decision workflow and Redis-backed lease operations, helping distinguish local quota evaluation from distributed coordination latency.
Key observations include:
traffic.decision— overall traffic-decision operationtraffic.policy.lookup— traffic-policy lookuptraffic.quota.evaluate— local quota evaluationtraffic.lease.allocate— lease allocationtraffic.lease.consume— consumption against an allocated leaseredis.lease.acquire— Redis lease acquisitionredis.lease.consume— Redis lease consumptionredis.lease.renew— Redis lease renewalredis.lease.release— Redis lease releaseThe local Docker Compose environment includes Jaeger for inspecting traces. Span emission depends on the operation and code path being executed.
See the OpenTelemetry Tracing Guide for configuration, local setup, test requests, and troubleshooting.
🧪 Testing & Validation
The automated suite covers:
Current test status
Redis integration suite
The Redis integration tests run against a real Redis 7 instance supplied by Testcontainers.
📈 Performance Validation
The system has been benchmarked with k6 in both single-node and distributed configurations.
Single-gateway baseline
Distributed 3-gateway benchmark
Comparison
Distributed lease evidence
During distributed validation:
This demonstrates that requests exercised the distributed lease path and contended for the shared global capacity pool.
🧯 Failure & Recovery Validation
A controlled multi-gateway failure test was executed against the deployed topology.
Gateway failure
One gateway was stopped while Redis and the other gateways remained available.
Traffic continued successfully through the surviving gateways.
Gateway recovery
The failed gateway was restarted:
The recovered gateway returned a healthy state and successfully resumed traffic evaluation.
What this validates
☁️ AWS Deployment
The project has also been deployed and validated on AWS using a multi-node topology:
AWS components used:
The deployment was validated for:
See the complete deployment procedure in
docs/aws-deployment.md.🔒 Production Readiness
This repository is intentionally production-oriented in architecture and engineering practices, while the current AWS environment remains a controlled reference deployment.
Implemented production-oriented practices
Additional hardening required for a high-risk production rollout
Before using this exact AWS baseline for a security-sensitive production workload, add and verify:
This distinction is deliberate: the architecture is designed around production concerns, but a production claim should only be made after the surrounding security, reliability, and operations controls are also in place.
🧱 Project Structure
🧭 Design Principles
Separate local and global state
Local quota enforcement handles the hot path, while Redis coordinates the shared global budget.
Make distributed mutations atomic
Operations that update multiple Redis structures are coordinated through Lua scripts.
Bound lease size
Nodes acquire bounded chunks of capacity instead of reserving the entire global pool.
Reclaim unused capacity
Released and expired leases return unused capacity to the shared pool.
Keep metrics operationally safe
Metrics remain low-cardinality so request-specific identifiers do not become monitoring labels.
Validate behavior, not just compilation
Distributed behavior is validated using integration tests, multi-node runtime tests, load tests, and controlled failure scenarios.
📚 Documentation
Detailed project documentation lives under
docs/:These documents cover requirements, architecture, distributed coordination, failure modes, deployment topology, and measured validation results.
🗺️ Roadmap
Completed
Future enhancements
✅ Validation Status
👤 Author
Yash Chauhan
📄 License
This repository does not currently declare a finalized open-source license.
Add a
LICENSEfile and update this section before publishing the project for external reuse.Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.