Memory requirements for real-time editing session management
Problem description
I am currently working on real-time editing of issue descriptions and one of the things that we need to build is a collaborative session model. This allows us to track the current state of a user on a specific document (Is a user online?, Is a user active on a document or away?). The session model should be entirely stored in Redis and sessions are relatively short-lived (e.g. editing an issue, creating a merge request).
To develop this feature, I want to make sure to not exhaust any infrastructure resources, in particular memory usage on the Redis instances. As described in this tech design, we need to store the relationship between a user and a session and which users are present in a session. In addition to that, we might also track the last known activity timestamp (UNIX epoch) of a user in a session.
The expectation is that the model will not consume more than 100 M of memory at any time, given the number of concurrent active users does not exceed 150k.
Number of sessions | Number of users | Expected memory usage |
---|---|---|
150000 | 150000 | ~53 M |
75000 | 150000 | ~46 M |
This is based on baseline overhead of a Redis set, the assumption that sets with a cardinality < 512 are optimized if the set members are all integers. This has been measured on a MacBook M1, so the numbers will most likely diverge based on the actual infrastructure this runs on (e.g. x64 Linux vs ARM).
I would like to figure out if the infrastructure team is ok with me using the existing SharedState redis instance and consume up to 100 M of memory in total. In terms of sharding keys, we could try to modify the key design to allow for that (similar to the followers/following example in this issue), but this has not been explored yet.
To roll out the feature, we will use feature flags and monitor memory usage on the Redis instance.
Example usage of the session model
This is one of the features this session model can unlock (Who is also working on this issue?)