Skip to content

feature request: postgresql broker #6

Open

Description

@egorsmkv

psqlpy now supports LISTEN/NOTIFY functionality psqlpy-python/psqlpy#121

so we can use it as the broker

Activity

  1. alario-tang commented on Nov 6, 2025

    @alario-tang

    +1

  2. danfimov commented on Dec 6, 2025

    @danfimov
    Member

    You can try taskiq-postgres[psqlpy]. I already implemented broker there

  3. alario-tang commented on Dec 21, 2025

    @alario-tang

    I want to add some context from real-world usage.

    There is already a community implementation (e.g. taskiq-postgresql / taskiq-postgres) that provides a PostgreSQL-based broker (often together with result backend and scheduler source). This suggests there is a real demand for running Taskiq without Redis/RabbitMQ, especially in environments where PostgreSQL is already the only allowed infrastructure component.

    In my case, I would strongly prefer not to introduce Redis at all, mainly because of the additional operational complexity and the cost of maintaining a highly available Redis cluster in production. Being able to rely solely on PostgreSQL (which we already operate in HA) is a big advantage.

    From my perspective, an official PostgreSQL broker would be valuable even if it is initially minimal:

    • no hard requirement to cover scheduler or result backend
    • focus on correctness, visibility, and Taskiq-native semantics
    • clear guidance on trade-offs (LISTEN/NOTIFY vs polling, locking strategy, etc.)

    Even a “simple but official” broker would give users more confidence than relying on third-party implementations for core message delivery.

    Happy to help with testing, design discussion, or documenting constraints if this moves forward.

  4. s3rius commented on Dec 22, 2025

    @s3rius
    Member

    There's a few problems with using postgres as a task queue. As I see it:

    1. postgres' NOTIFY sens message to ALL clients. Which means that you will receive as many messages as you have workers. Which is undesireable behavior in most of cases.
    2. NOTIFY/LISTEN mechanism doesn't have any delivery guarantess. In redis for example we use streams to ensure deliverability and acknowledgement.
    3. Using tables for tracking tasks will have poor performance. Because all operations will have select-for-update semantics which has its performance cost.

    Considering all from the above I think that implemening full broker interface on postgres can have negative impact on experience of using taskiq.

  5. alario-tang commented on Dec 23, 2025

    @alario-tang

    Thanks a lot for the detailed explanation – it makes sense and I absolutely agree that PostgreSQL is not a great fit for a high-throughput, default broker in Taskiq.

    That said, I think there is still a valid space for a non-default, “constrained” PostgreSQL broker implementation, if its design explicitly avoids some of the pitfalls you mentioned and clearly documents the trade-offs.

    On the NOTIFY broadcasting point:

    • It’s true that NOTIFY sends to all listeners, but many existing PG-based job queues treat NOTIFY only as a “wake up signal”, not as the actual transport for tasks.
    • The real dequeue semantics can be implemented on top of a jobs table with something like SELECT … FOR UPDATE SKIP LOCKED LIMIT 1, so only one worker actually locks and processes a given row. In that model, extra NOTIFY wakeups mostly result in harmless “no work” checks, not duplicated processing.

    On reliability:

    • I fully agree that NOTIFY/LISTEN itself has no delivery guarantees.
    • But if we rely on the jobs table as the source of truth (with status = pending/in_progress/done, timeouts, retries, etc.), NOTIFY is only an optimization to reduce polling latency. If a notification is dropped, workers will still eventually pick up pending jobs via polling, so reliability comes from the table + transactions rather than from NOTIFY.

    On performance and UX:

    • I completely agree that a PostgreSQL broker should never be the recommended solution for high volume, short-lived tasks. Redis/RabbitMQ are much better there.
    • However, there are environments where:
      • PostgreSQL is already operated in HA,
      • introducing Redis requires significant extra operational and HA cost,
      • and the expected throughput is modest (e.g. tens of workers, tens/hundreds of jobs per second).
    • For those setups, even a slower broker with well-understood limits and a clearly documented “this is not for high throughput” label could be very valuable.

    From my perspective, it would already be a big win to have:

    • a minimal, officially supported PostgreSQL broker,
    • clearly marked as non-default / limited throughput / best-effort,
    • using NOTIFY only as a wake-up hint and putting reliability in the job table and transaction model.

    This way, the default Taskiq experience remains unchanged (Redis/RabbitMQ for serious queues), but users who consciously accept the trade-offs and want to stay on PostgreSQL only still have an official, supported path.

    Happy to help with experimentation, benchmarks on realistic workloads, or writing documentation about the constraints, if that would be helpful.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions