0Pricing
Erlang OTP: Distributed & Fault-Tolerant Systems Programming · Lección

Backpressure y patrones de regulación de carga

Mantenga la estabilidad de los sistemas bajo sobrecarga mediante patrones de backpressure, limitación de velocidad y descarte de carga basados en primitivas de OTP.

Backpressure y patrones de regulación de carga es una lección gratuita de Erlang OTP: Distributed & Fault-Tolerant Systems Programming en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Erlang OTP: Distributed & Fault-Tolerant Systems Programming, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Erlang OTP: Distributed & Fault-Tolerant Systems Programming incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

What Is Backpressure?

When work arrives faster than a system can process it, queues grow and latency explodes. Backpressure is the practice of signalling producers to slow down so the system stays stable instead of melting down.

The Unbounded Queue Problem

An async gen_server:cast never blocks the caller, so its mailbox can grow without limit under load — the system runs out of memory before it ever rejects work.

Synchronous Calls as Backpressure

Using gen_server:call instead of cast makes the caller wait until the server is ready, naturally throttling producers to the server speed.

Reply = gen_server:call(worker, {process, Job}, 5000).

Bounded Queues

Maintain an explicit counter of in-flight work and reject or block new requests once a limit is reached, rather than letting the mailbox grow.

handle_call({job, J}, _From, #{n := N} = S) when N < 100 ->
    {reply, ok, S#{n := N + 1}};
handle_call({job, _}, _From, S) ->
    {reply, {error, overloaded}, S}.

Load Shedding

Under extreme load, the best move can be to shed low-priority work fast — returning an error immediately — to protect the system for high-priority requests.

Rate Limiting with Tokens

A token-bucket limiter grants a fixed number of permits per interval; requests beyond that wait or fail. This caps throughput predictably.

case take_token(Bucket) of
    ok -> do_work();
    empty -> {error, rate_limited}
end.

Measuring Pressure

The mailbox length of a bottleneck process is a live pressure gauge. Monitor it and trigger shedding before it grows dangerous.

process_info(Worker, message_queue_len).

Pooling for Throughput

A pool of worker processes (e.g. via poolboy) bounds concurrency: requests queue for a free worker, giving natural backpressure with controlled parallelism.

Circuit Breakers

When a downstream dependency is failing, a circuit breaker opens to stop sending requests for a cooldown period, preventing pileups and giving the dependency time to recover.

Timeouts as Protection

Always give gen_server:call a finite timeout. An unbounded wait lets a stuck server block callers indefinitely; a timeout converts a hang into a fast, recoverable error.

case catch gen_server:call(srv, req, 2000) of
    {ok, R} -> R;
    _ -> {error, busy}
end.

Choosing a Strategy

Combine patterns: synchronous calls for natural throttling, bounded queues to cap memory, rate limiting for fairness, and load shedding plus circuit breakers as last-resort protection.

Quick Check

Test your load regulation knowledge.

Recap

You learned to keep systems stable under overload:

  • Backpressure signals producers to slow down
  • Synchronous call throttles naturally; bounded queues cap memory
  • Rate limiting enforces fairness; load shedding protects priority work
  • Worker pools bound concurrency; circuit breakers stop downstream pileups
  • Monitor mailbox length as a live pressure gauge

Preguntas frecuentes

¿La lección «Backpressure y patrones de regulación de carga» es gratis?

Sí — el texto completo de «Backpressure y patrones de regulación de carga» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Erlang OTP: Distributed & Fault-Tolerant Systems Programming, actualiza a CoddyKit PRO. El curso de Erlang OTP: Distributed & Fault-Tolerant Systems Programming incluye 4 lecciones en total.

¿Qué aprenderé en «Backpressure y patrones de regulación de carga»?

Mantenga la estabilidad de los sistemas bajo sobrecarga mediante patrones de backpressure, limitación de velocidad y descarte de carga basados en primitivas de OTP. Practicas Erlang OTP: Distributed & Fault-Tolerant Systems Programming con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Erlang OTP: Distributed & Fault-Tolerant Systems Programming?

No se requiere experiencia previa. Erlang OTP: Distributed & Fault-Tolerant Systems Programming en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Backpressure y patrones de regulación de carga»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Erlang OTP: Distributed & Fault-Tolerant Systems Programming?

Sí. Cada lección de Erlang OTP: Distributed & Fault-Tolerant Systems Programming incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Diseño para alta disponibilidad
  2. Patrones de consenso distribuido
  3. Casos prácticos de Erlang OTP
  4. Backpressure y patrones de regulación de carga
← Volver a Erlang OTP: Distributed & Fault-Tolerant Systems Programming