Skip to main content
ARCHOS 525 BLUEPRINT · /d/dgm_rate-limiter

Distributed Rate Limiter (token bucket on a sharded counter store)

11 COMPONENTS · 13 FLOWS · UPDATED 2026-11-19
GITHUB README / PR PREVIEW CARD
[![Distributed Rate Limiter (token bucket on a sharded counter store) — ArchOS Architecture](https://archos.sageideas.dev/d/dgm_rate-limiter/opengraph-image)](https://archos.sageideas.dev/d/dgm_rate-limiter)

*Interactive architecture diagram powered by [ArchOS Studio](https://archos.sageideas.dev/d/dgm_rate-limiter)*
NOTION / DOCS / CONFLUENCE EMBED
<iframe src="https://archos.sageideas.dev/embed/dgm_rate-limiter" width="100%" height="580" style="border:1px solid rgba(240,236,225,0.14);border-radius:6px;" loading="lazy" title="Distributed Rate Limiter (token bucket on a sharded counter store) — Interactive in ArchOS"></iframe>
PORTABLE MERMAID SPEC (GITHUB / NOTION / RFC)
flowchart LR
  client_0[("API Client")]
  rs_1["Resource server"]
  lb_2["Layer 7 load balancer"]
  gw_3["API gateway"]
  rl_4[("Rate limiter")]
  secrets_5[("Secrets manager")]
  cache_6[("Distributed cache")]
  standby_7[("Hot standby")]
  tsdb_8[("Time-series database (TSDB)")]
  alerting_9[("Alerting")]
  capacity_10["Capacity Estimate"]
  client_0 -->|"1. Calls with a JWT · HTTPS"| lb_2
  lb_2 -->|"2. Forwards (mTLS) · HTTP/2"| gw_3
  gw_3 -->|"3. Asks for decision (mTLS) · gRPC"| rl_4
  rl_4 -->|"4. Runs bucket script (mTLS) · RESP"| cache_6
  cache_6 -->|"5a. Returns token count · RESP"| rl_4
  cache_6 -->|"5b. Replicates asynchronously · RESP"| standby_7
  rl_4 -->|"6. Returns decision · gRPC"| gw_3
  gw_3 -->|"7a. Forwards allowed (mTLS) · HTTP/2"| rs_1
  gw_3 -->|"7b. Returns HTTP 429 · HTTP/2"| lb_2
  lb_2 -->|"8. Relays HTTP 429 · HTTPS"| client_0
  rl_4 -->|"Exports (OTLP) · OTLP"| tsdb_8
  tsdb_8 -->|"Supplies metrics · HTTP"| alerting_9
  secrets_5 -->|"Supplies credentials · HTTPS"| rl_4

COMPONENT STACK (10)

  • API ClientSTATEFUL
    Calls the API from an untrusted network
  • Resource serverSTATELESS
    Backend API that sheds load when overloaded
  • Layer 7 load balancerSTATELESS
    Ends TLS, stamps a trace id, spreads requests
  • API gatewaySTATELESS
    Checks the JWT and scope, then asks the limiter
  • Rate limiterSTATEFUL
    Token bucket decision; fails open if the cache is down
  • Secrets managerSTATEFUL
    Holds the cache password and TLS certificates
  • Distributed cacheSTATEFUL
    Redis Cluster: the limiter picks the shard by key
  • Hot standbySTATEFUL
    Replica of each shard, kept in a different zone
  • Time-series database (TSDB)STATEFUL
    Stores allow and reject counts over time
  • AlertingSTATEFUL
    Pages on-call when rejects or errors spike

REQUEST & DATA FLOW (13)

  1. API Client → Layer 7 load balancer (Calls with a JWT)[HTTPS]
  2. Layer 7 load balancer → API gateway (Forwards (mTLS))[HTTP/2]
  3. API gateway → Rate limiter (Asks for decision (mTLS))[gRPC]
  4. Rate limiter → Distributed cache (Runs bucket script (mTLS))[RESP]
  5. Distributed cache → Rate limiter (Returns token count)[RESP]
  6. Distributed cache → Hot standby (Replicates asynchronously)[RESP]
  7. Rate limiter → API gateway (Returns decision)[gRPC]
  8. API gateway → Resource server (Forwards allowed (mTLS))[HTTP/2]
  9. API gateway → Layer 7 load balancer (Returns HTTP 429)[HTTP/2]
  10. Layer 7 load balancer → API Client (Relays HTTP 429)[HTTPS]
  11. Rate limiter → Time-series database (TSDB) (Exports (OTLP))[OTLP]
  12. Time-series database (TSDB) → Alerting (Supplies metrics)[HTTP]
  13. Secrets manager → Rate limiter (Supplies credentials)[HTTPS]
Configure NGINX / Postgres / K8s →60-Sec L4–L7 Diagnostic →