Throttles an action performed by a P2P system using a synchronized partitioned quota.
This project demonstrates how to use Akka Clustering to synchronize Int
values between distributed
nodes that sum
to a predefined value. These Int
values can be used for local throttles to ensure an aggregate throttle
equal to the sum
.
This is useful in the context of throttling a specific action performed by a distributed system, such as requests to a legacy web service, without introducing a single point of failure or active/passive redundancy.
-
Identify the maximum number of times the action can be performed across the system (per second). This is the
shared quota
. -
Each node creates its own
ActorSystem
and joins the same Akka Cluster. -
Akka's
auto-down
feature is leftdisabled
to ensure there is only oneleader
in the event of network partitions. -
Nodes receive leave/join events and adjust their
local quota
accordingly. -
The
leader
node is responsible for handling the remainder when theshared quota
does not evenly divide. -
Nodes that cannot see the
leader
set theirlocal quota
to0
.
Synchronization of the shared quota
is eventually consistent. Todo: determine consistency SLA. Consider first seed node,
timeouts from failure-detector, and perhaps latency between receiving CRDT payloads? The latter may be covered by
failure-detector.