Closed JWCook closed 2 years ago
The identity
of the item is something that is related to the system's existing logic (eg: user_id).
The bucket_name
is something that we use to categorize our data in redis, avoiding duplication with other keys and making it easier to filter/search.
I mean, thinking about the case where multiple backends / microservices are dealing with user-ids at the same time and have different limiting rates, isn't it easier to separate this service A's bucket from service B's bucket etc. We can leave such responsibility to the developer - but I think enforcing this convention will save our friends from certain problems in future.
Ah, that makes sense. I didn't think of the case of multiple services using the same IDs. Thanks for explaining.
Here's a question about initializing Redis buckets:
https://github.com/vutran1710/PyrateLimiter/blob/e3f2fd94abf96bd2977c03445e742267f1de19c7/pyrate_limiter/bucket.py#L125-L140
It requires a
bucket_name
, which is used in addition toidentity
as the key of the Redis list used by that bucket. But isn'tidentity
already unique for each bucket?Limiter.bucket_group
has exactly one bucket instance per identity. Couldbucket_name
be removed, or does that have some other purpose that I'm missing?