A popular AI summary expires from a cache just as twenty readers request it. If each request independently starts generation, one missing entry becomes twenty expensive operations. Request coalescing can let equivalent callers wait for one in-flight operation instead.
Go’s singleflight package provides a duplicate-call suppression mechanism: one execution for a key can share its result with concurrent callers. This is different from a cache, which stores a result for later requests. The two techniques can be used together.
“Equivalent” is the design decision
For an AI workflow, the visible prompt alone may not identify the work. Model version, system instructions, source-document version, generation settings and user permissions can all change what a valid result means.
A fictional document-summary service might form a key from the tenant, document revision, prompt revision, model and settings. If two users are not entitled to the same source material, they must not share a result simply because their requests contain similar words.
Walk through one cache miss
- Check whether a valid authorised cached result already exists.
- Join or create the in-flight operation for the complete key.
- Let one worker perform the generation.
- Validate the result before storing or returning it.
- Release waiting callers according to their own cancellation and timeout rules.
This is a conceptual sequence, not production code. Multi-process deployments need an approach appropriate to where coordination occurs; an in-memory group in one process does not automatically coordinate every server.
Decide how failures behave. A shared upstream error should not create an uncontrolled retry wave, and a caller abandoning its wait should not necessarily cancel work still needed by others. Streaming responses add their own buffering and subscriber-lifecycle questions.
Measure actual upstream calls, waiting time, shared failures and cache hits separately. Fewer calls is useful only if results remain correct for each caller. Coalescing should remove redundant work while preserving authorization, versioning and the meaning of the requested output.

