Stop optimizing for throughput. Start optimizing for survival. A physics-based approach to load shedding in Go.
Most servers are configured to be Samurais.
When a wave of traffic hits, they accept every single request with honor. They will fight until their CPU melts. They will queue requests until their memory explodes. They will try to serve everyone, and because of that, they end up serving no one.
They die a hero's death, taking your uptime with them.
I don't like Samurai servers. I like servers that survive.
That is why I built Lawbench.
The Problem with Heroism
When a system is under extreme load, it hits a physical limit called the Universal Scalability Law (USL). Specifically, it hits the Retrograde Point.
At this point, accepting one more request doesn't just slow down that specific user; it slows down everyone due to contention (fighting for locks) and crosstalk (coordination overhead). It is like a traffic jam: adding more cars doesn't move more people; it just makes everyone stop.
A "Samurai" server ignores this. It accepts the request. The queue grows. The database locks hold longer. The latency spikes from 100ms to 5 seconds. Finally, the health check times out, and Kubernetes kills the pod.
The irony? By trying to serve 100% of the traffic, you served 0%.
A Server That Knows When to Say No
Lawbench is a library that acts as a Thermodynamic Governor for your Go application. It monitors the internal physics of your system—specifically a metric called the Coupling Parameter ($r$).
When it detects that your server is entering a chaotic state ($r > 3.0$, a mathematical boundary where latency variance becomes infinite), it forces the server to stop being a hero.
It rejects the excess traffic.
It's Not Just an Error; It's a Signal
When Lawbench sheds load, it doesn't just slam the door. It buys you Time and Options.
Because the server isn't dead (it's just busy), it remains responsive. This allows you to do smarter things than just timing out:
- Instant Routing: A 1ms
503 Service Unavailableisn't just an error; it's a routing instruction. It tells the load balancer: "I am full, give this request to my neighbor." A 30-second timeout tells the load balancer nothing until it's too late. - Trigger Autoscaling: Because the server is still alive, it can report "I am full" to Kubernetes before latency spikes. You scale up proactively, not reactively.
- Graceful Degradation: Instead of a database query that hangs for 10 seconds, you can instantly return a "System Busy" JSON or a cached version of the page.
The Proof
I ran a torture test: 300 concurrent users hitting a standard Go server with 10% slow queries to simulate contention.
The Samurai Server (Without Lawbench):
Accepted everything.
- P95 Latency: 2 seconds.
- Result: It crashed. The metrics script couldn't even finish.
The Smart Server (With Lawbench):
It realized it was full. It shed 10% of the traffic.
- P95 Latency: 191ms.
- Result: The 90% of users who got in had a fast, perfect experience. The 10% got a fast error message instead of a slow timeout.
Bonus: Because Lawbench prevents retrograde scaling (where adding pods decreases throughput), one production strategy based on this math prevented $9,800/month in wasted Kubernetes over-provisioning.
The Code
This is the entire integration. No config files, no YAML, no "platform team" approval needed. Just Go middleware.
import "github.com/alexshd/lawbench"
// The Governor watches the physics
governor := lawbench.NewGovernor(1.5)
http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
// Check physics before doing work
if governor.ShouldShedLoad() {
// Option A: Return a fast 503 (Load Balancer retry)
// Option B: Return cached data
// Option C: Return a static "We are scaling up" message
http.Error(w, "Service at capacity", 503)
return
}
// Do the work
processRequest()
})
Conclusion
We often think "Robustness" means handling more pressure.
But in distributed systems, Robustness means knowing your limits.
Lawbench gives your application the intelligence to know when it is full, and the permission to say "No" so it can live to say "Yes" to the next user.
It is open source. It is tested. 107 tests passing.
Try it. Or don't. But the next time your pod crashes at 3 AM because it was "too polite to refuse traffic," remember: You chose honor over uptime.
Lawbench chooses survival.

Top comments (0)