You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the simplest case, counter values are just integers.
But then what if you wanted to count really large numbers. BigInt?
We needed to count percentages (calculated from other counters) such as spam rate. So Float? Or Double? Or even Decimal?
We will need to store counters as HLL values enabling us to approximately count unique values
We may want to support slotted counters to allow higher concurrent writes without locking
We will need to support counters over time, i.e., number of emails sent per month
We might want to support counters/events in external systems like Redis
It's hard to support these different representations in a single database table. We could make Counter::Value an STI table but then we'd be storing Integer, Float, HLL, and maybe JSONB columns for each counter.But maybe that's fine if those columns are nil since they only require ~1bit of storage??
Alternatively, the counter should write to different tables depending on the configuration?
…which gets be reconsidering having separate counter definitions. Perhaps values should just be Rails models? e.g.
# This will be stored on the counter_values table with an type value of "MyCounter" (i.e., using STI)classMyCounter < Counter::Value# Some configuration methods to specific what it is counting, conditionals, hooks etccount…end# This will be stored in the counter_hll table with a type value of "PageVisitsCounter"classPageVisitsCounter < Counter::HLL# some config…end
Using different tables might make sorting/filtering a little harder but probably doable.
The text was updated successfully, but these errors were encountered:
In the simplest case, counter values are just integers.
It's hard to support these different representations in a single database table. We could make Counter::Value an STI table but then we'd be storing Integer, Float, HLL, and maybe JSONB columns for each counter.But maybe that's fine if those columns are nil since they only require ~1bit of storage??
Alternatively, the counter should write to different tables depending on the configuration?
…which gets be reconsidering having separate counter definitions. Perhaps values should just be Rails models? e.g.
Using different tables might make sorting/filtering a little harder but probably doable.
The text was updated successfully, but these errors were encountered: