Kuadrant / limitador

Rate limiter
Apache License 2.0
58 stars 21 forks source link

Data Model #182

Open alexsnaps opened 1 year ago

alexsnaps commented 1 year ago

The current data model

The data model resides in the limitador crate source and is broken down into these few structs: Namespace, Limit and finally Counter.

Interestingly these types fulfill different roles and are closer to Data Transfer Objects (DTOs) than an actual data model. Counters are mostly used as a lookup mechanism to their actual values. In the memory store, the actual values are held in the InMemoryStorage.counters’ TtlCache, that cache is also responsible for applying the correct TTL. Redis is responsible for the same TTL enforcement and stores the values as plain integers in a Hash, keyed by Counter. Limits are too mostly used to look Counters up. They are also used as DTOs for the REST API exposed by the server, e.g. when querying for known counters.

Note: The RocksDbStorage is slightly different as the underlying RocksDB doesn’t have built-in TTL support. That feature was built in an ExpiringValue type that handles the expiry explicitly, while holding the current counter’s value.

Things to address

eguzki commented 3 weeks ago

@alexsnaps is this still in the scope of v1?