8000 Add Configurable Pub/Sub Subscriber Backpressure Strategy · Issue #1118 · kividbio/kividb · GitHub
[go: up one dir, main page]

Skip to content

Add Configurable Pub/Sub Subscriber Backpressure Strategy #1118

Backlog

Description

@JituRewar

Problem

Currently, KiviDB disconnects a Pub/Sub subscriber when its pending output buffer exceeds the configured client-output-buffer-limit pubsub limits.

A subscriber is disconnected in two scenarios:

  • Hard limit: When its pending output buffer reaches the configured hard limit.
  • Soft limit: When its pending output buffer remains above the soft limit for longer than the configured soft_seconds.

This behavior is currently fixed, with no configuration option to choose an alternative backpressure strategy.

For high-throughput, fire-and-forget Pub/Sub use cases, disconnecting slow subscribers may be undesirable, especially when occasional message loss is acceptable.

Proposed Solution

Introduce a new configuration option:

pubsub-backpressure

It should support two strategies:

  • disconnect (default): Preserve the existing behavior. Disconnect subscribers when they exceed the configured hard or sustained soft output buffer limits.
  • drop: Instead of disconnecting slow subscribers, discard incoming messages that would exceed the configured output buffer limits while keeping the subscriber connected.

The configuration should be accessible through CONFIG GET and dynamically adjustable through CONFIG SET.

Expected Behavior

  1. Existing deployments should retain the current behavior by default (disconnect).
  2. In drop mode, messages that exceed the subscriber's configured output buffer limits should be discarded.
  3. The subscriber should remain connected when messages are dropped.
  4. Pending buffer accounting should remain accurate after dropped messages.
  5. Once the subscriber's pending buffer drains below the configured limits, normal message delivery should resume.
  6. The soft-limit background monitoring mechanism should not disconnect subscribers in drop mode.

Configuration Example

CONFIG SET pubsub-backpressure drop
CONFIG GET pubsub-backpressure

To restore the existing behavior

CONFIG SET pubsub-backpressure disconnect

Testing

  • Verify that drop mode discards messages when the hard limit is exceeded without disconnecting the subscriber.
  • Verify that sustained soft-limit violations do not disconnect subscribers in drop mode.
  • Verify that pending buffer accounting remains correct after dropped messages.
  • Verify that message delivery resumes after the subscriber's buffer drains.
  • Verify runtime switching between drop and disconnect.
  • Verify CONFIG GET, CONFIG SET, and invalid configuration values.
  • Ensure the default disconnect mode preserves existing behavior.

Activity

  1. added
    enhancement
    on Dec 1, 2026
  2. JituRewar commented on Dec 1, 2026

    @JituRewar
    ContributorAuthor

    Hi @murtazayusuf Before raising pr please take a look to this.

  3. murtazayusuf commented on Dec 1, 2026

    @murtazayusuf
    Contributor

    Thanks @JituRewar, the write-up is clear and the shape is right: an opt-in pubsub-backpressure drop with disconnect staying the default. Go ahead with a PR. 1.3.0's scope is closed, so I've put this on the "after 1.3.0" milestone and it merges once that release is out.

    A few things I'd want the PR to settle:

    • What can be dropped. Only published messages (message, pmessage, smessage). Replies to SUBSCRIBE/UNSUBSCRIBE/PING and RESP3 client-tracking invalidations always go through, since a client cannot recover from a missing one.
    • Drops are visible. A dropped message is invisible to the subscriber, so the server has to count them: a total in INFO stats (say pubsub_dropped_messages) and a per-client count in CLIENT LIST / CLIENT INFO. Please document that PUBLISH's return value counts subscribers the message was dropped for or not, whichever you choose, and test it.
    • Which limit drops. In drop mode I'd drop at the hard limit and also once the soft limit has been exceeded for soft_seconds, so memory per subscriber stays bounded the same way as today. A subscriber with no pubsub limit configured (0 0 0) behaves as now.
    • Whole messages only. A message is either fully queued or not at all; never a partial frame.
    • Cost. The check sits on the publish path only, one relaxed load of the setting per delivery; nothing in the command path for other commands.
    • Docs. A section in the configuration docs and a CHANGELOG line under [Unreleased], describing what the server does in each mode.

    If this is your first engine PR the CLA bot will ask you to sign; it takes a minute.

  4. added this to the after 1.3.0 milestone on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0