Skip to content

Exercise 4: Resolve PostgreSQL Transaction Abort in Batch Consumer #7

Description

@harsharajkumar-273

Goal

Ensure resilient database batch updates when message failures occur.

Problem

In src/consumer.ts, when processing a batch of events inside a PostgreSQL transaction (BEGIN ... COMMIT), if a single metric write fails due to constraint violations or database issues, PostgreSQL marks the active transaction as aborted. The loop keeps trying to issue queries on the aborted client, the final COMMIT fails, and the worker loops indefinitely re-consuming the exact same batch.

Task

  1. Resolve the aborted transaction block issue in the consumer batch loop.
  2. You can rewrite the writes as a single bulk INSERT query (using dynamic values) with ON CONFLICT DO NOTHING to avoid individual line failures.
  3. Alternatively, utilize SQL SAVEPOINT sub-transactions to isolate individual insert errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions