Skip to content

Feature: Google SRE Client-Side Adaptive Throttling #42

Description

@cinar

Description: Implement Google's mathematical approach to handling overload (detailed in the SRE Book). Instead of relying strictly on a circuit breaker that entirely opens or closes, adaptive throttling calculates a dynamic probability of dropping requests locally before they even hit the network, based on the server's recent success/failure ratio.

  • Architecture & Implementation Requirements:

    • State Tracking: Maintain two counters (ideally within the sync.Pool or a lightweight ring buffer): requests (attempted calls) and accepts (successful calls).
    • The Math (Proportional Probability): Before initiating a request, calculate the rejection probability using Google's formula: max(0, (requests - K * accepts) / (requests + 1)) (Where K is a configurable multiplier, defaulting to 2).
    • Execution Logic: If P_{drop} > 0, generate a random float between 0.0 and 1.0. If the random number is less than P_{drop}, immediately return ErrThrottledLocally without making the network call.
  • Acceptance Criteria:

    • Must be mathematically accurate and update counters atomically to avoid race conditions.
    • Must gracefully decay older stats so the client eventually resumes sending traffic when the server recovers.
    • Must implement clean code changes without over-refactoring the existing Do loop.
  • Resources:

    • Google SRE Book: Handling Overload (Client-Side Throttling)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions