Skip to content

[Feature]: Implement asynchronous PostgreSQL stores if #181 validates the design #266

Open

Description

@MisterVVP

Problem

The current TaskStore, PushNotificationStore and TaskAwarePushNotificationStore interfaces are synchronous. If an application uses non-blocking transport and execution APIs but then blocks during PostgreSQL queries, database waiting still consumes application threads.

The correct solution may be genuine libpq non-blocking I/O, but this introduces significant transaction, lease, cancellation and lifecycle complexity. Production work must use the architecture selected in #181 instead of choosing an API and implementing every store at once.

Goal

Subject to the #181 decision, add an opt-in, production-quality non-blocking PostgreSQL store path for task and push-configuration operations without removing or changing existing synchronous store interfaces.

Ownership and issue boundaries (v0.6.0)

Owns: Conditional opt-in production non-blocking PostgreSQL store implementations for task and push-configuration operations, only if #181 demonstrates a justified benefit; preserve synchronous stores.

Prerequisites and integration: Blocked on an explicit evidence-backed go/limited decision from #181. Align with #268 cancellation contract; #268 gRPC completion and #270 HTTP runtime are not prerequisites for the standalone I/O engine. May defer to v0.7.0 without expanding the issue count if research does not justify v0.6.0 delivery.

Must not absorb: No automatic pool sizing, libpq pipeline mode, speculative schema changes, synchronous API replacement, network transport refactor or blocking PQexec on std::async/worker pool disguised as async DB I/O.

Issue management: Retain this issue and use separate independently reviewable PRs for the checkpoints below. Close only when final acceptance criteria pass. Do not pull future checkpoints into earlier PRs.

Implementation PR checklist

  • PR 1 — Adopt [Research/Performance]: Evaluate asynchronous PostgreSQL I/O for SDK stores #181 architecture; implement shared non-blocking libpq operation/lease/socket-readiness lifecycle with one read and one write, failure/cancel tests.
  • PR 2 — Add transaction begin/commit/rollback across suspension, locks/revisions and failure recovery; discard ambiguous/broken connections rather than returning them to pool.
  • PR 3 — Implement selected TaskStore and push-config operations plus non-worker async in-memory equivalents; ensure conformance with existing sync semantics.
  • PR 4 — [Enhancement]: Add opt-in async unary server execution and cancellation #268 integration, deterministic PostgreSQL cancel/connection-loss/shutdown tests, controlled baseline performance evidence, installed-consumer docs and full validation.

PR merge rule: Narrow changes, deterministic scope-specific tests, documented lifecycle ownership, and applicable AGENTS.md validation. Measure performance-sensitive behavior against equivalent baseline workloads. Preserve synchronous behavior.

Detailed technical requirements — scope and implementation phases

Phase 1 — Adopt the researched contract and I/O primitive

  • Record the [Research/Performance]: Evaluate asynchronous PostgreSQL I/O for SDK stores #181 evidence and chosen API/result model (callback, task or coroutine). The async interface should cover operations actually needed by the async server, rather than inventing a universal async persistence framework.
  • Implement the shared non-blocking libpq operation lifecycle, connection ownership and socket readiness integration.
  • Define when a lease may be returned, when it must be discarded and how shutdown/cancellation coordinate with operations in flight.
  • Validate one read and one write end-to-end before moving all store behavior to the new mechanism.

Checkpoint: Core I/O engine and connection invariants can be reviewed before transaction integration.

Phase 2 — Transactions and store operations

  • Implement task and push-config operations using the established non-blocking path, sharing authoritative SQL/state-transition helpers with sync code where doing so does not obscure ownership or create duplication bugs.
  • Cover begin/commit/rollback across suspension points, advisory locks, task revision checks, task-aware push-config writes and failure recovery.
  • On cancellation, query failure, server shutdown or connection loss, ensure a transaction either rolls back safely or its connection is closed/discarded; never return ambiguous state to the pool.
  • Add an async-compatible in-memory store path without creating a worker thread to adapt trivial in-memory operations.

Checkpoint: Async store conformance matches sync stores for data semantics and transaction invariants.

Phase 3 — Integration and performance proof

Non-goals

  • Removing sync stores, replacing libpq/PostgreSQL, speculative SQL/schema migrations or automatic pool resizing.
  • Implementing libpq pipeline mode without separate evidence.
  • Wrapping blocking PQexec calls in std::async/a worker pool and describing that as non-blocking DB I/O.
  • Changing network HTTP or gRPC transport internals as part of store implementation.

Acceptance criteria

  • [Research/Performance]: Evaluate asynchronous PostgreSQL I/O for SDK stores #181 explicitly recommends production async PostgreSQL work and defines the API/performance bar.
  • Existing public store interfaces and their users remain source-compatible.
  • Task and push-config async operations use real non-blocking libpq socket progress, not per-request blocking workers.
  • Lease ownership, connection pooling, transaction commit/rollback, cancellation, errors and shutdown are deterministic.
  • Damaged or incomplete transactions never reenter the reusable pool.
  • Equivalent async in-memory semantics exist without hidden workers.
  • Async store conformance/integration tests, required TCK and performance checks pass.
  • Representative benchmarks demonstrate the justification identified by [Research/Performance]: Evaluate asynchronous PostgreSQL I/O for SDK stores #181; synchronous performance does not materially regress.

Activity

  1. added this to the v0.6.0 milestone on Oct 5, 2026
  2. added
    enhancement
    performance
    and removed on Oct 5, 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

    enhancementperformance

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions