日本文化をWebで身近にする個人開発者
日本文化と日常の小さな楽しみを、Webで気軽に体験できるサイト 一禅堂 を個人で企画・開発しています。 一禅堂では、今の恋愛運や相手との関係を楽しく占える「恋みくじ」、毎日の運勢を気軽に楽しめる「おみくじ」、漢字の読み方・意味・筆順を調べられる「漢字辞典」など、実用性と日本らしい体験を大切にしたコンテンツを公開しています。 Hashnodeでは、サイト開発を通して得た知識を中心に、フロントエンド開発、UI/UX、多言語対応、プライバシーに配慮した設計、SEO、静的サイトの運用について発信します。 一禅堂の 恋みくじ 公式サイト 漢字辞典: 漢字書き順 神社 おみくじ
Markdown supported · ⌘↵ to post
The next scaling concern is hot-key distribution. A global limit stored under one Redis key can become a serialization point even when the cluster has plenty of total capacity. Per-tenant keys scale better, while truly global limits may require a hierarchical design.
Time handling is easy to underestimate in a distributed limiter. If application servers calculate refills using their own clocks, clock skew can produce inconsistent decisions. Keeping time calculation close to the authoritative Redis state makes the behavior easier to reason about.
Token bucket is a practical choice because it separates the sustained rate from the permitted burst size. Those two values should be configured independently; otherwise, increasing throughput may accidentally allow much larger traffic spikes than the downstream service can absorb.
Using a Lua script for refill, validation, and token consumption is the key step here. Without atomic execution, concurrent clients can read the same token count and both succeed, allowing the real request rate to exceed the configured limit.
haleo
A production rate limiter also needs an explicit failure policy. When Redis is slow or unavailable, should the service fail open, fail closed, or temporarily use a local fallback? The correct answer depends on whether availability, cost protection, or abuse prevention is the higher priority.