Skip to content

Replace process-wide limiter with shared api-core middleware - #84

Merged
paulyhedral merged 2 commits into
developfrom
feature/fix-rate-limiting-per-client-ip
Sep 9, 2026
Merged

paulyhedral merged 2 commits into
developfrom
feature/fix-rate-limiting-per-client-ip

Conversation

@paulyhedral

Copy link
Copy Markdown
Contributor

Part of the platform-wide rate-limiting cut-over: sweetrpg/platform#106
(OpenSpec change fix-rate-limiting-per-client-ip, tasks 2.4 + 5.1 + 5.2).

Code

  • Delete the process-wide rate.NewLimiter(1, burst) - one busy caller could
    exhaust the budget for every caller, and N replicas made the effective limit
    N times looser than configured.
  • Register ratelimit.Middleware(redisPool, ratelimit.DefaultOptions())
    (per-client/IP, Redis-backed, fail-closed 503) built from
    api-core.go/util.RedisPool().
  • Startup pings Redis and warns if unreachable.
  • Bump api-core.go v0.1.1 -> v0.3.1.

Dev overlay / secrets

  • RATE_LIMIT_* tier vars (api-core defaults 120/60, 30/60).
  • REDIS_HOST/REDIS_PORT for the namespace cache Service.
  • New secrets/cache.yaml ExternalSecret (api-cache, Akeyless
    /sweetrpg/admin/cache/auth -> REDIS_PASS) + kustomization entry + base
    deployment envFrom.

Verification

go build ./..., go vet ./..., go test ./... all pass.
kustomize build kubernetes/overlays/dev renders the tier/Redis vars and the
api-cache secret. Two concurrent client IPs now get independent budgets.

@paulyhedral paulyhedral added enhancement New feature or request dependencies Pull requests that update a dependency file go Pull requests that update go code labels Sep 9, 2026
@paulyhedral paulyhedral self-assigned this Sep 9, 2026
…dleware (#106)

Delete the process-wide rate.NewLimiter(1, burst) - one busy caller could
exhaust the budget for every caller, and N replicas made the real limit N
times looser. Register api-core.go/ratelimit.Middleware (per-client/IP,
Redis-backed, fail-closed 503) built from util.RedisPool. Bump api-core.go to
v0.3.1.

Dev overlay gains the RATE_LIMIT_* tier vars, REDIS_HOST/PORT for the
namespace cache Service, and an api-cache ExternalSecret for REDIS_PASS.
@paulyhedral
paulyhedral force-pushed the feature/fix-rate-limiting-per-client-ip branch from 34b1e66 to 509eadb Compare September 9, 2026 16:24
@paulyhedral
paulyhedral merged commit 3c518b6 into develop Sep 9, 2026
1 check passed
@paulyhedral
paulyhedral deleted the feature/fix-rate-limiting-per-client-ip branch September 9, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant