Fault tolerant idioms for distributed systems.
The retry API is available in tank.retry
. Currently there are two types of retry strategies:
The usage is pretty simple. You pass the parameters for the strategy, a catch-fn
to select which exceptions are retriable and the body that should run. Here's an example:
(require '[tank.retry])
(tank.retry/with-exponential-backoff 10 5 (constantly true)
...)
If it fails to successfully run in the amount of attempts (in this case 5), it will throw an exception.
The circuit breaker pattern is really useful for avoiding cascading failures in distributed systems. It behaves like an electrical circuit breaker, meaning that after some failed attempts it will fail immediately. In case of a immediate fail, it throws an exception.
The way it is implemented is by using a leaky bucket algorithm.
Here's an example:
(require '[tank.circuit-breaker])
(defn http-request! [] ...)
(let [circuit-breaker (tank.circuit-breaker/circuit-breaker 10 100)]
(tank.circuit-breaker/call! circuit-breaker http-request!))
This circuit breaker object can be shared between several calls (eg: calls to multiple endpoints from a single service can share a single circuit breaker).
Copyright © 2018 Caio Oliveira
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close