Skip to content

Backpressure

Documentación en español de Backpressure, alineada con el monorepo y la guía inglesa.

Entrada rápida

Producer → [Token Bucket] → [Ring Buffer] → [Circuit Breaker] → Consumer
              rate-limit       absorb bursts     protect when overwhelmed
typescript
import { BackpressureController } from '@commander/core';

const controller = new BackpressureController({
  tokenBucket: {
    maxTokens: 100,
    refillRatePerSecond: 50,
  },
  ringBuffer: {
    capacity: 200,
  },
  circuitBreaker: {
    failureThreshold: 0.5,    // 50% failure rate opens breaker
    recoveryTimeoutMs: 30000, // Wait 30s before half-open
    halfOpenMaxRequests: 10,  // Probe requests in half-open
  },
});
typescript
// Check if a request should be admitted
const admission = controller.tryAdmit();

if (admission.allowed) {
  // Process the request
  const result = await processRequest(request);
  controller.recordSuccess();
} else {
  // Request rejected — return 429 or queue
  return { status: 429, reason: admission.reason };
}
StagePurposePattern
Token BucketRate-limits admission (tokens per second)Leaky bucket
Ring BufferAbsorbs burst traffic (fixed-size, O(1) insert/evict)LMAX Disruptor
Circuit BreakerProtects consumer when overwhelmedHystrix 3-state
MetricDescription
backpressure_tokens_availableCurrent tokens in bucket
backpressure_ring_buffer_occupancyRing buffer fill ratio
backpressure_circuit_breaker_stateCLOSED, OPEN, or HALF_OPEN
backpressure_requests_admitted_totalTotal admitted requests
backpressure_requests_rejected_totalTotal rejected requests
backpressure_requests_spilled_totalTotal spilled from ring buffer

Notas

  • CLI monorepo: cliEntry.ts · tras build: commander
  • Métricas: 25 proveedores · 5 topologías · 18 tools · 6700+ tests
  • Firmas API exactas: monorepo / API overview

Relacionado

MIT — Hecho para orquestación multi-agente.