skip to Main Content

My question is about a fundamental functionality of the distributed cache, my use case is a rate limiter implementation on a load balanced environment, each request from the same endpoint should increment a request-counter for that endpoint, I’m trying to understand how a distributed cache works in this situation when each request is directed to a different (load balanced) cluster node, is the endpoint request-count stored on a single node of the cluster? in this case the network load is inefficient, isn’t it?, can I configure the cluster to replicate the data for reads? wouldn’t this cause consistency issues and write penalties on the cache cluster when increment is preformed on the counter? Do distributed caches use any quorum based mechanisms?

Thanks.

2

Answers


  1. This is a fundamental question regarding distributed systems. It is covered basically under CAP Theorem:

    https://en.wikipedia.org/wiki/CAP_theorem

    C = Consistent, A = Available, P = Partitioned (distributed)

    You can only have 2 of the 3 – you have to make trade offs according to your use case.

    My experience is with Hazelcast (http://www.hazelcast.org) which by default is an AP system using a data partitioning scheme. Hazelcast also has a CP subsystem to offer guaranteed consistency over availability.

    https://hazelcast.com/blog/riding-the-cp-subsystem/

    Coincidentally I advised a bit on a rate limiting system using Hazelcast a year or so ago. It did precisely what your talking about. You just have to take the pieces and architect a system that meets your neeeds.

    Login or Signup to reply.
  2. Cluster quorum, replicated maps – they are all there in Hazelcast but if I understood your requirement correctly, you do not need any of them. I think what you are asking for can have a very simple answer:

    • Use a distributed map
    • Assign a unique identifier to each endpoint and use this identifier as "key" when a request is generated from that endpoint.
    • As for the value, you have various options to keep the count. For example – a simple AtomicInteger (Java SDK’s, not Hazelcast IAtomicInteger).
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search