โ† Back to list

๐Ÿšฆ Load Shedding: The Last Line of Defense

Why Saving the System Means Saying โ€œNoโ€

Dolly ยท 2026-01-06 16:35 ยท 50 claps ยท 2.0 min read
#load #shedding #salt #line #defense
Open on Medium โ†—
Wiki topics: PFI ยท Personal Finance

๐Ÿšฆ Load Shedding: The Last Line of Defense

๐Ÿšฆ Load Shedding: The Last Line of Defense

๐Ÿšฆ Load Shedding: The Last Line of Defense

Why Saving the System Means Saying โ€œNoโ€

SEO keywords: load shedding, Spring Boot overload protection, microservices resilience, backpressure, capacity control

When traffic spikes, most systems do one thing:

They try harder.

More threads More retries More CPU More pods

And thatโ€™s exactly how they die.

Healthy systems donโ€™t try harder under overload. They shed load.

๐Ÿšจ The Fatal Instinct: Be Helpful Under Pressure

Your service is overloaded.

What does it do?

  • Accept more requests
  • Queue them
  • Slow down
  • Time out

No errors. No alarms.

Just a slow collapse.

This is not resilience. This is politeness at scale.

๐Ÿง  What Load Shedding Actually Means

Load shedding is:

Intentionally rejecting work to preserve system health.

Not failure. Not rudeness.

Self-defense.

๐Ÿ’ฃ Why Scaling Is Not a Solution

Auto-scaling:

  • Reacts late
  • Costs money
  • Amplifies bad traffic
  • Spreads failure

If your system collapses before scaling triggers, youโ€™re already down.

โš ๏ธ Where Overload Really Happens

Not at:

  • CPU 100%
  • Memory OOM

But at:

  • Thread pool saturation
  • Connection pool exhaustion
  • Queue buildup
  • Event loop blocking

By the time CPU is high, itโ€™s too late.

๐Ÿ” Load Shedding vs Backpressure

Backpressure is polite.

Load shedding is necessary.

๐Ÿงช Simple Load Shedding in Spring Boot (Semaphore)

@Component
public class LoadSheddingFilter implements Filter {
private final Semaphore semaphore = new Semaphore(100);
    @Override
    public void doFilter(
            ServletRequest request,
            ServletResponse response,
            FilterChain chain)
            throws IOException, ServletException {
        if (!semaphore.tryAcquire()) {
            HttpServletResponse resp = (HttpServletResponse) response;
            resp.setStatus(429);
            resp.getWriter().write("Too Many Requests");
            return;
        }
        try {
            chain.doFilter(request, response);
        } finally {
            semaphore.release();
        }
    }
}

This:

  • Caps concurrency
  • Prevents thread exhaustion
  • Keeps latency predictable

โšก Rate Limiting Is Load Shedding

@Bean
public Bucket4jConfiguration bucketConfig() {
    return Bucket4jConfiguration.builder()
        .addLimit(Bandwidth.simple(100, Duration.ofSeconds(1)))
        .build();
}

429 responses are not errors.

They are signals.

๐Ÿง  Load Shedding in Reactive Systems

@GetMapping("/data")
public Mono<Response> getData() {
    return Mono.just("ok")
        .limitRate(100)
        .onErrorReturn(
            RejectedExecutionException.class,
            fallbackResponse()
        );
}

Reactive systems must shed load early โ€” or event loops die.

๐Ÿ’ฅ Why Load Shedding Saves Healthy Traffic

Without shedding:

  • All users get slow responses

With shedding:

  • Some users get fast responses
  • System stays alive
  • Recovery is instant

Partial failure is better than total failure.

๐Ÿ“‰ Metrics That Tell You When to Shed

Watch:

  • Active thread count
  • Queue depth
  • Request latency slope
  • Timeout frequency

Load shedding should trigger before timeouts spike.

๐Ÿง  Production Rule of Thumb

If youโ€™re timing out:

Youโ€™re already late.

Load shedding should happen earlier.

๐Ÿš€ Final Takeaway (The Line That Spreads)

Resilient systems donโ€™t collapse gracefully. They refuse gracefully.

Saying โ€œnoโ€ to some traffic is how you say โ€œyesโ€ to the system.


๋ฉ”ํƒ€๋ฐ์ดํ„ฐ
post_id
517866a2f45e
slug
load-shedding-the-last-line-of-defense-517866a2f45e
url
https://medium.com/@gangoladeepa/load-shedding-the-last-line-of-defense-517866a2f45e
canonical_url
https://medium.com/@gangoladeepa/load-shedding-the-last-line-of-defense-517866a2f45e
author_url
https://medium.com/@gangoladeepa
status
ok
fetched_at
2026-06-20 20:29:01