Skip to content

add storage module for retaining messages in kv store #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

jkarneges
Copy link
Member

@jkarneges jkarneges commented Apr 26, 2025

As a first step towards implementing message durability, this PR adds a module, storage, that allows saving a single message per topic. It contains a Storage trait and a KV Store based implementation.

The module is not used anywhere yet, but the plan is to use it to:

  • Implement retained message support in the MQTT handler, by saving messages when publishing, and replaying them when subscribing.
  • Implement saving/replaying in the HTTP handler, by saving messages when POST'ing, and replaying them when SSE subscribing.

KV item metadata is used to keep a version and an optional expiration time. The version consists of a generation number (randomly generated) and a sequence number (strictly increasing); these values will be needed to implement ordered & reliable message delivery. The expiration time maintained in the metadata allows us to treat the item's content as expired even if the item itself persists. This is mainly useful for when a topic's message expires and is later replaced by a new message, we can reuse the generation/sequence.

Writing to KV Store is limited to 1 write/second per key. This module attempts to work around this slightly, by retrying a few times if a write fails. This way, serial writes to the same topic from a single writer should not encounter write-rate errors and instead may experience a backpressure effect. However, multiple writes in parallel to the same topic could result in errors due to the write-rate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant