Skip to the content.

5. Use singleflight for debounce

Date: 2023-10-15

Status

Accepted

Context

When our system experiences a surge in duplicate requests, especially during cache misses, it leads to an unnecessary load, redundant computations, and potential bottlenecks. This not only impacts system performance but can also degrade the user experience due to increased latency.

Decision

We’ve chosen to implement the singleflight package as it provides a proven solution to debounce redundant requests, ensuring that for any given function with a particular key, only one execution happens. This choice was made after evaluating other potential solutions, with singleflight emerging as the most effective and widely adopted in the industry.

Implementation involves:

  1. Pinpointing areas with frequent duplicate requests.
  2. Applying singleflight.Group structures therein.
  3. Ensuring waiting requests get results from a single computation, optimizing system load.

Available Packages for Different Languages

Consequences

Pros:

Cons:


Post-implementation, we’ll monitor the system’s performance, specifically focusing on areas where singleflight was implemented. Any anomalies will trigger an analysis, and if necessary, a rollback plan is in place to revert the changes.