Redis-Synchronized Time for Distributed Circuit Breaker Coordination - #920
Redis-Synchronized Time for Distributed Circuit Breaker Coordination#920bolshakov wants to merge 7 commits into
Conversation
Review price tag🟢 195 effective lines — about 23–59 min (down from 29–72 min) of focused review (based on 200–500 lines/hour). This is within the range where reviewers find the most issues per line, and small changes usually receive feedback the fastest. Spread across many files. This PR changes 16 files — more than about 9 in 10 PRs touch. Each extra file is another piece of context a reviewer has to load and hold at once. Why these numbers?These minutes are what careful defect-finding costs at 200–500 lines/hour — the rate review studies report, not how long a skim takes. "Effective lines" already exclude generated files and lockfiles. Treat the rates and the 200/400 thresholds as guardrails, not laws. |
83dad59 to
9ee8232
Compare
9ee8232 to
4b2bb17
Compare
4b2bb17 to
53dd451
Compare
53dd451 to
7846430
Compare
| raise ArgumentError, "Unknown time unit: #{unit}" | ||
| end | ||
| Timecop.travel(Time.now + seconds) | ||
| sleep(seconds) |
There was a problem hiding this comment.
no time traveling in feature tests anymore
87f78bc to
6a81f63
Compare
6a81f63 to
a904df5
Compare
Complete implementation of Phase 2a (state transitions) and Phase 2b (metrics) to use Redis as the authoritative time source across distributed instances. Changes: - TimeTravel helper for test time control with Redis stack awareness - State transition scripts updated to use now() - Metrics scripts (unbounded/window) updated to use now() - Float precision preserved in TimeTravel for sub-millisecond accuracy - All supporting Ruby code updated to match Lua changes Tests: 832 passing (2 edge cases: rapid-fire updates in same millisecond)
With Redis-synchronized time via now(), out-of-order timestamps are impossible: - All events on same Redis instance see monotonically increasing time - Scripts execute serially on Redis - Time only moves forward Simplify logic: always update with current timestamp instead of checking if new timestamp > previous timestamp. This reduces code complexity while maintaining all functionality. Tests: All 832 passing
a904df5 to
5146ac3
Compare
Implement Redis as the authoritative time source for all circuit breaker operations, eliminating time skew issues across multi-instance deployments. This allows Stoplight to reliably coordinate state transitions and metrics aggregation in distributed environments.
Problem
In multi-instance deployments, clock skew between instances can cause:
last_error_at/last_success_attimestamps can go backwardsThe circuit breaker depends on reliable timestamps for its entire state machine and metrics, making time synchronization critical.
Solution
Make Redis the authoritative time source via a
now()Lua function that callsredis.call("TIME"):now()-- no Ruby timestamps passed to Luanow()--unbounded_metricsandwindow_metricssynchronizedArchitecture
Time flow in distributed deployment:
All instances call the same
now()function, eliminating clock skew.