Skip to content

Middleware

Daniel Pepper edited this page Mar 13, 2022 · 2 revisions

Berater's middleware layer makes modifying limiter behavior easy, and ships with useful ones to get you started. It works much like Rack/Rails middleware and is powered by meddleware.

Fail Open

If Redis briefly times out or crashes altogether, it shouldn't take limiters and your whole app with it. This middleware improves resiliency by ensuring limiters fail open, so your app keeps working as expected even if Redis does not.

Berater.middleware.use Berater::Middleware::FailOpen

Load Shedding

All work is important, but some may be more important. This is especially true when systems approach their limits and we're forced to decide which work gets done and which does not. Specifying priority levels and pre-emptively shedding lower priority work helps ensure that the most important work gets done. The naive approach offered by this middleware is simple, yet effective. (a more optimal implementation is under development)

Berater.middleware.use Berater::Middleware::LoadShedder


limiter.limit(priority: 1) { ... } # high priority
limiter.limit(priority: 5) { ... } # low priority

Statsd

Capture key metrics like limiter usage and utilization. Currently supports Datadog with rich tagging.

statsd = Datadog::Statsd.new
Berater.middleware.use Berater::Middleware::Statsd, statsd
Clone this wiki locally