nats-server
nats-server copied to clipboard
Distributed atomic counter support in JetStream KV
Feature Request
Add Distributed Atomic Counter support to JetStream KV.
Use Case:
Proposed Change:
- add supporting code to kv
- add command-line support
- a new flag for
kv addsubcommand to specify whether the stream backing a bucket should be a file stream or a memory stream, e.g.:nats kv add my_bucket --replicas 1 --history 5 --STORAGE=FILEnats kv add my_bucket --replicas 1 --history 5 --STORAGE=MEMORY
- two new subcommands:
incrby x, e.g.:nats kv INCRBY 20 my_bucket my_key_1decrby x, e.g.:nats kv DECRBY 10 my_bucket my_key_1
- a new flag for
- allow interacting with the counters programmatically
- 1st phase: via publishing messages to dedicated subjects; this would allow the new feature to be used before the official clients catch up.
- 2nd phase: via Synadia official JetStream client(s).
Who Benefits From The Change(s)?
- Synadia - by closing the feature gap between JetStream and more popular solutions.
- Synadia - by making clients and users happy. Who doesn't need or use counters in production?
- JetSstream users - who can say no to happiness ?
Alternative Approaches
- The competition
- Apache Kafka
- Apache Pulsar
- Other software
- Redis
- RDBMS
- etc
The Slack thread describing the use case has been archived, but I hope that the use cases are still easy enough to imagine.
I am currently doing this this by publishing +1s and -1s to a stream, then consuming that stream with another client that eventually puts the accumulated results into a kv store. It would be nice to skip that step.
We continue to think through some of these patterns.
For now, the client can read and update only if no updates got in between. If the update rate is high this might not be a good solution however.
Is anyone still working/thinking about this?
it's on the short term roadmap yes
@ripienaar any chance this will be implemented in 2.11?
I believe it's still the plan yes