8 Practical Go Concurrency Patterns from a Cache Performance Optimization

cover

This article is drawn from a performance improvement to an authorization service written in Go. The subject is API key validation caching: how to shorten the query path on a cache miss, how to keep every request from being dragged down when Redis fails, and how to shut down background workers correctly. The code comes from a real project; I trimmed it for readability and renamed things to be generic.

On the surface these are 8 independent Go patterns, but they serve one goal: under cache degradation, Redis failure, and service shutdown, hold the line that “a revoked key must never be allowed through” while still winning back latency and throughput. Near the end, a Redis outage timeline strings all 8 patterns together on one request path.

[Read More]

從一次快取效能優化,看 8 個實用的 Go Concurrency Pattern

cover

這篇文章整理自一個用 Go 撰寫的授權服務的效能改善。主題是 API Key 驗證快取:如何縮短 cache miss 的查詢路徑、在 Redis 故障時不拖垮每一筆請求,以及正確關閉背景 worker。程式碼取自實際專案,為了閱讀方便做了刪減,名稱也改成通用的寫法。

表面上這是 8 個獨立的 Go pattern,但它們服務同一個目標:在快取降級、Redis 故障、服務關閉的各種情況下,守住「已撤銷的 key 絕對不能被放行」,同時把延遲和吞吐量換回來。 文末有一段 Redis 故障時間線,把 8 個 pattern 串在同一條請求路徑上。

[Read More]