Redis Stream 적용기 의 후속편이다. Redis Stream 은 stream key 를 하나의 큐로 사용한다. 문제는 redis cluster 모드에서 redis stream key 는 하나의 노드에만 저장이 되기떄문에 부하분산이 되지 않는다.
실질적인 분산을 위해서라면 stream key 자체를 분산시켜야한다. 일단 redis cluster 은 최대 16384 해시 슬롯 모듈러 까지 지원하긴 함. 예시로 user-notification 이 기존 stream key 라고 가정. 어찌되었든 userId 는 가장 많이 사용되는 값이고 이거랑 stream key 를 엮어서 user-notification+{userId} mod 16 의 노드에 할당하면 분산처리 가능하다.
여기서 가장 주의할 점은 클러스터에 노드가 추가될 떄, 기존에 할당된 키들이 새로운 슬롯에 재배치되어야 한다는 것이다. 이를 위해서는 키의 해시 값을 기반으로 슬롯을 재계산하고, 필요한 경우 데이터를 재분배하는 로직이 필요하다. 이게 사실 되게 어려운 듯… 직접 관리한다는게 까다로움ㅜㅜ
This is a follow-up to the Redis Stream adoption post. Redis Stream uses a stream key as one queue. The problem is that in Redis Cluster mode, a Redis Stream key is stored on only one node, so load is not distributed.
For real distribution, the stream key itself needs to be distributed. Redis Cluster supports up to 16,384 hash slots with modulo. As an example, assume user-notification is the existing stream key. Since userId is the most frequently used value anyway, you can combine it with the stream key and assign it to a node with user-notification+{userId} mod 16, making distributed processing possible.
The most important point here is that when a node is added to the cluster, the existing assigned keys need to be relocated to the new slots. For that, logic is needed to recalculate slots based on the hash value of the key and redistribute data if necessary. This seems quite difficult in practice. Managing it directly is tricky.