ikyriak / IdempotentAPI

A .NET library that handles the HTTP write operations (POST and PATCH) that can affect only once for the given request data and idempotency-key by using an ASP.NET Core attribute (filter).
MIT License
270 stars 39 forks source link

Support idempotency in a cluster environment #34

Closed ikyriak closed 1 year ago

ikyriak commented 2 years ago

To support idempotency in a cluster environment (i.e., a group of multiple server instances), we could use Distributed Locks with Redis via the proposed Redlock algorithm.

Rast1234 commented 2 years ago

My 5 cents: Redis itself is difficult to clusterize (= broken and unmanageable), so it'd be great to have an abstraction, maybe existing caching abstraction will do?

ikyriak commented 2 years ago

Hello @Rast1234

Thank you for your input. That's true. An abstraction would be placed. However, we have to keep in mind that there are applications on single servers (where Distributed Locks are not needed).

I was thinking of providing an implementation for Redis. However, the following library also seems nice to use various technologies easily.

ikyriak commented 2 years ago

Hello @Rast1234

The feature of supporting idempotency in a Cluster Environment (i.e., a group of multiple server instances) using Distributed Locks has been included in the v2.0.0-RC.01 release 🎆🎉.

Refactoring has been performed to include additional abstractions and distinguish the Caching (IIdempotencyCache), Distributed Locks (IDistributedAccessLockProvider), and Accessing of them (IIdempotencyAccessCache).

Currently, we support the following two implementations for Distributed Locks:

In addition, the DistributedLockTimeoutMilli attribute option is included to configure the time the distributed lock will wait for the lock to be acquired (in milliseconds).

Can you please check if this is working for your case?

Rast1234 commented 2 years ago

Impressive! We already implemented minimal working idempotent-ish solution for our case but i'll tell the team and put a task into our backlog. This looks very promising!