Kit / Kit/excess_flow

Investigate replacing mutex with a redis transaction

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
21
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Per @ankopainting suggestions in https://github.com/ConvertKit/excess_flow/issues/1:

The second thing i just wanted to comment on (sorry for the nitpick), is the mutex is unnecessary. Instead you could use a redis transaction. Here is what I'm doing;

```
ret = redis.pipelined do
redis.zremrangebyscore full_key, 0, clear_before_timestamp # remove requests past period
redis.zcard full_key # count of how many requests we've received
redis.zadd full_key, current_timestamp, SecureRandom.uuid
redis.expire full_key, period
end
```

The redis docs say;
All the commands in a transaction are serialized and executed sequentially. It can never happen that a request issued by another client is served in the middle of the execution of a Redis transaction. This guarantees that the commands are executed as a single isolated operation.

https://redis.io/topics/transactions

Need to investigate how viable this option is and if mutex can be replaced with a transaction it could clean up code a bit.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the mutex and Redis operations involved in rate limiting. Compare their behavior with the pipelined transaction example and the linked Redis transactions documentation. Done means determining whether the mutex can be removed and documenting the required changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
redis, ruby
Domain
backend, databases
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.