apache / apache/kvrocks

Receive notification for SET and DEL events on replicas (minimal implementation of notify-keyspace-events)

Open
#2,915 5 comments 1 reaction 1 assignee Claimed by @Aetherance View on GitHub
enhancement
Dominant language
C++
Stars
4.4k
Forks
658
Avg merge
1d 20h
Merged PRs (30d)
10

Description

### Search before asking

- [x] I had searched in the [issues](https://github.com/apache/kvrocks/issues) and found no similar issues.

### Motivation

Applications connected to the KVRocks read-only replica use their own cache to reduce response latency and minimize direct requests to KVRocks. However, the application must react to key changes in order to provide up-to-date responses.

We don’t use TTLs for keys and don’t expect key expiration events — this is also difficult to implement due to the nature of the KVRocks underlying storage (rocksdb). As minimum we need to react on SET and DEL commands, apps itself can control the subscription using PSUBSCRIBE and PUNSUBSCRIBE commands, it will allow to replace Redis/Valkey with minimal effort.

KVRocks is excellent for distributing data across the fleet without wasting RAM, and it’s a very strong candidate to replace our current Redis storage. Keyspace events are the last missing piece preventing us from fully switching from Redis/Valkey to KVRocks.

### Solution

From what I understand, KVRocks uses a WAL internally to replicate changes. This means that when the WAL is applied on replicas, it should be possible to detect key changes and emit events to applications with subscriptions by pattern (PSUBSCRIBE/PUNSUBSCRIBE).

### Are you willing to submit a PR?

- [ ] I'm willing to submit a PR!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.