gofr-dev/gofr · error

burst must be greater than requests per window

Error message

burst must be greater than requests per window

What it means

errBurstLessThanRequests (rate_limiter_config.go:12) is returned by RateLimiterConfig.Validate when Burst < Requests per window — the burst capacity must be at least the steady-state request rate or the limiter would throttle below its own configured rate. Validate still self-heals by setting Burst = int(Requests).

Source

Thrown at pkg/gofr/service/rate_limiter_config.go:12

package service

import (
	"errors"
	"fmt"
	"net/http"
	"time"
)

var (
	errInvalidRequestRate     = errors.New("requests must be greater than 0 per configured time window")
	errBurstLessThanRequests  = errors.New("burst must be greater than requests per window")
	errInvalidRedisResultType = errors.New("unexpected Redis result type")
)

const (
	unknownServiceKey = "unknown"
	methodHTTP        = "http"
	methodHTTPS       = "https"
)

// RateLimiterConfig with custom keying support.
type RateLimiterConfig struct {
	Requests float64                    // Number of requests allowed
	Window   time.Duration              // Time window (e.g., time.Minute, time.Hour)
	Burst    int                        // Maximum burst capacity (must be > 0)
	KeyFunc  func(*http.Request) string // Optional custom key extraction
	Store    RateLimiterStore
}

View on GitHub (pinned to 187eb24962)

Solutions

  1. Set Burst >= Requests, e.g. Requests: 100, Burst: 100 (or higher for headroom).
  2. Handle Validate's returned error; note Validate already corrected Burst, so the error is also a signal your config didn't express intent.
  3. Derive Burst from Requests programmatically instead of hardcoding independent values.

Example fix

// before
cfg := &service.RateLimiterConfig{Requests: 100, Window: time.Minute, Burst: 10}
// after
cfg := &service.RateLimiterConfig{Requests: 100, Window: time.Minute, Burst: 120}
Defensive patterns

Strategy: validation

Validate before calling

if float64(cfg.Burst) < cfg.Requests {
	return fmt.Errorf("burst (%d) must be >= requests (%f)", cfg.Burst, cfg.Requests)
}

Type guard

func validBurst(cfg *service.RateLimiterConfig) bool {
	return cfg != nil && float64(cfg.Burst) >= cfg.Requests
}

Try / catch

if err := cfg.Validate(); err != nil {
	if errors.Is(err, errBurstLessThanRequests) {
		log.Printf("burst corrected to requests rate by Validate: %v", err)
	}
}

Prevention

When it happens

Trigger: Validate finds float64(config.Burst) < config.Requests — e.g. Requests: 100, Burst: 10 — typically after Burst was left at 0 (then defaulted to 10) or set deliberately lower than Requests.

Common situations: Raising Requests in config without revisiting Burst; assuming Burst is optional and leaving it unset while Requests > 10; copying an example tuned for a low request rate.

Related errors


AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01). Data as JSON: /api/errors/6d2c5376a563dbae. Report an issue: GitHub.