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]

讓 AI Agent、MCP Server、CLI 安全登入:從 PKCE 到 Gateway 的實作工作坊

讓 AI Agent、MCP Server、CLI 安全登入:OAuth 2.0、PKCE 與 MCP

2026 年 10 月 14 日,我在 Hello World Dev Conference 2026 帶了一場 90 分鐘的實作工作坊:「讓 AI Agent、MCP Server、CLI 安全登入」。這篇文章把工作坊的觀念與練習路線整理下來,讓沒到場的朋友也能從自己的筆電開始,走過一次 MCP 的授權流程。

當 Agent 能讀文件、查工單、寫入資料,接上工具只是開始。真正要回答的是:這次操作代表誰?可以做哪些事?這顆 Token 能用在哪個服務?出事後,要怎麼停止它的權限?

上一篇企業身分認證治理實戰談的是整體架構,這篇則把焦點拉近到一個 HTTP 請求:從沒有 Token 時的 401,一路追到登入、取得授權,以及 Server 決定接受或拒絕的那一刻。

[Read More]

MCP 2026-07-28 Specification Update Explained: Stateless Core, MRTR, Tasks, and Security Hardening

cover

MCP 2026-07-28 is not a minor release that merely renames fields. It moves the protocol core from “establish a bidirectional session, then exchange messages inside it” toward a model that better fits Web infrastructure: each request is self-describing, independently routable, and explicitly cacheable; interactions and long-running work have clear protocol contracts. This directly addresses common production problems: sticky routing, rolling deployments, gateways that cannot inspect bodies, retrying after disconnects, and OAuth trust boundaries.

This article draws on the official release announcement, changelog, specification, Go SDK v1.7.0, and nine executable examples in go-training/mcp-2026-07-28. Their roles differ: the specification defines wire semantics, the SDK defines the public Go API, and the examples and tests only demonstrate the behavior they cover. Tasks in particular are standardized in the specification, while v1.7.0 does not yet provide a complete typed API.

By the end, you should be able to answer four questions: how MCP becomes easier to scale horizontally, how to complete an interaction without a session, what a gateway can safely observe, and which layer server, client, and platform owners should migrate first.

For hands-on verification, refer to the training examples for 01 Stateless, 02 Subscriptions, 03 MRTR, 04 Cache, 05 HTTP headers, 06 Deprecations, 07 MCPGODEBUG, 08 Authorization, and 09 Extensions / Tasks.

AreaCommon 2025-11-25 model2026-07-28 focusPrimary beneficiary
ConnectionInitialization and a session bind subsequent trafficPer-request metadata and optional discoveryServer / platform
InteractionServer-initiated reverse RPCMRTR retries and the Tasks extensionClient / agent
ListingsRefetch or guess at cachingttlMs, cacheScope, and invalidationClient / LLM host
HTTPRouting requires parsing JSON bodiesMcp-* headers verified against the bodyGateway / SRE
ExtensibilityThe core keeps growingExplicit extensions with bilateral opt-inSDK / platform
[Read More]

MCP 2026-07-28 規格更新全解析:從無狀態核心、MRTR 到 Tasks 與安全強化

cover

MCP 2026-07-28 不是一次把欄位改名的小改版。它把協定核心從「先建立雙向 session,再在裡面交換訊息」改為更接近 Web 基礎設施擅長處理的模式:每個 request 自我描述、可獨立路由、可明確快取,互動與長工作則有明確的 protocol contract。這正好處理 production 最常見的麻煩:sticky routing、滾動部署、gateway 看不懂 body、斷線重試與 OAuth 信任邊界。

本文以官方 release announcement、changelog 與 specification、Go SDK v1.7.0,以及可執行的 go-training/mcp-2026-07-28 九組範例為依據。三者的角色不同:規格定義 wire semantics,SDK 定義公開 Go API,範例與測試只證明它實際覆蓋的行為;尤其 Tasks,規格已正式化,但 v1.7.0 尚未有完整 typed API。

讀完你應該能回答四件事:怎麼讓 MCP 更容易水平擴展、怎麼在無 session 下完成互動、gateway 能安全觀察什麼,以及 server、client、platform 各自該先遷移哪一層。

想邊讀邊驗證,可直接對照教材的 01 Stateless、02 Subscriptions、03 MRTR、04 Cache、05 HTTP headers、06 Deprecations、07 MCPGODEBUG、08 Authorization 與 09 Extensions / Tasks。

面向2025-11-25 常見模型2026-07-28 的重點主要受益者
連線initialization 與 session 綁住後續流量per-request metadata、optional discoveryserver/platform
互動server-initiated reverse RPCMRTR retry、Tasks extensionclient/agent
清單重抓或各自猜 cachettlMs、cacheScope、invalidationclient/LLM host
HTTProuting 要解析 JSON bodyMcp-* headers 並比對 bodygateway/SRE
擴充core 不斷長大雙方 opt-in extensionsSDK/platform
[Read More]

Optimizing Gitea Act Runner Connection Load: Reducing from 1,300 req/s to 170 req/s

cover

Gitea Act Runner is the execution component of Gitea Actions, responsible for fetching CI/CD tasks from the Gitea Server and reporting execution results. As more teams self-host Gitea, the HTTP request volume between Runners and the Server has become a bottleneck on the Server side. This article documents how we analyzed and resolved this problem, reducing the request volume from approximately 1,300 req/s to approximately 170 req/s for 200 Runners — an 87% reduction.

Update (2026-04-20): This article originally described the design after PR #819 merged. A follow-up, PR #822, revealed during code review that #819 had introduced a concurrency regression for Runners with capacity > 1, and addressed it with a “single poller + semaphore” architecture. See the new section at the end: Follow-up: Single Poller with Semaphore (PR #822).

[Read More]

Gitea Act Runner 連線負載優化:從 1,300 req/s 降到 170 req/s 的實戰紀錄

cover

Gitea Act Runner 是 Gitea Actions 的執行元件,負責從 Gitea Server 領取 CI/CD 任務並回報執行結果。隨著越來越多團隊自架 Gitea,Runner 與 Server 之間的 HTTP 請求量成為了 Server 端的瓶頸。本文記錄我們如何分析並解決這個問題,將 200 個 Runner 的請求量從約 1,300 req/s 降到約 170 req/s,降幅 87%。

更新(2026-04-20):本文原本描述 PR #819 合併後的設計。後續 PR #822 在 code review 中揭露 #819 對 capacity > 1 的 Runner 引入了一個 concurrency regression,並用「單一 poller + semaphore」架構再次修正。請見文末〈後續修正:Single Poller with Semaphore(PR #822)〉章節。

[Read More]

The Next Step for AI Agents: API + CLI + Skills Architecture

cover

In previous posts, I introduced the concept of Agent Skills and showed how to build an AI-driven development workflow with Claude Code + GitHub Copilot Review. As more products and teams embrace AI Agents, a clear architectural pattern is emerging: API + CLI + Skills. This isn’t a framework or protocol — it’s a pragmatic three-layer architecture that enables any product to become “agent-friendly” quickly.

[Read More]

AI Agent 的下一步:API + CLI + Skills 架構

cover

在之前的文章中,我分別介紹了 Agent Skill 的概念以及如何用 Claude Code + GitHub Copilot Review 打造 AI 驅動的開發流程。隨著越來越多產品和團隊開始擁抱 AI Agent,一個清晰的架構模式正在浮現:API + CLI + Skills。這不是某個框架或協議,而是一種務實的三層架構,讓任何產品都能快速變得「對 Agent 友善」。

[Read More]

Building a Unified API Gateway for Cross-Cloud AI Services: A Secure and Scalable Enterprise Solution

blog logo

In today’s enterprise environment, Generative AI technology has become key to enhancing business efficiency and innovation. However, with the diversification and decentralization of AI services, how to uniformly manage and call these services has become a challenge. This article will introduce how to use Golang to develop a unified API Gateway for cross-cloud AI services, achieving a secure and scalable enterprise-level solution.

This was my second public talk at the 2025 iThome CloudSummit Taiwan. Below is the outline of the talk.

  1. Authentication and Authorization
  2. Multi-Cloud AI Backend Integration (Azure OpenAI, AWS Bedrock, Google Gemini AI, etc.)
  3. Traffic Control and Resource Management
  4. Monitoring and Metrics Aggregation
[Read More]