We’re rolling out tiered pricing with per-tenant API quotas (e.g., Free: 100 requests/hour, Pro: 5,000/hour) and need a single, low-overhead rate-limit layer across all authenticated endpoints in our Flask services. Please implement a before_request middleware that identifies the caller’s tenant and plan, enforces the correct limit with minimal latency, and returns the right headers. Store real-time counters in Redis using a sliding window (atomic INCR + EXPIRE on keys like rate_limit:<tenant_id>:<timestamp_bucket>) rather than MySQL. On success, include X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset. If the limit is exceeded, immediately return 429 with a JSON error and a Retry-After header. For billing, add a periodic job that rolls up the Redis counts into hourly/daily totals in the api_usage_logs table in MySQL. The goal is platform stability and monetization, so please keep per-request overhead as small as possible.