Skip to content

Async Producer + Buffered Records - #4

Merged
Ret2Hell merged 5 commits into
mainfrom
dev
Mar 19, 2026
Merged

Ret2Hell merged 5 commits into
mainfrom
dev

Conversation

@Ret2Hell

@Ret2Hell Ret2Hell commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Switched event production from synchronous to asynchronous for improved throughput and responsiveness.
    • Enhanced metrics tracking to monitor success rate, failures, and latency separately instead of errors only.
    • Improved producer buffering and retry behavior for more reliable event delivery.
  • Chores

    • Updated Go toolchain to version 1.26.0.

@coderabbitai

coderabbitai Bot commented Mar 19, 2026 •

Copy link
Copy Markdown
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: e33c5c64-4fa0-4f7f-b25c-fec3e20f1114

📥 Commits

Reviewing files that changed from the base of the PR and between 60055ed and c26fe47.

📒 Files selected for processing (1)
  • internal/producer/producer_test.go
✅ Files skipped from review due to trivial changes (1)
  • internal/producer/producer_test.go

📝 Walkthrough

Walkthrough

Refactors message production from synchronous to asynchronous, adds success/failure/latency metrics, updates producer configuration (buffering, retries, linger), moves metrics initialization earlier, updates Go toolchain to 1.26.0, and adapts tests and handler integration to async semantics.

Changes

Cohort / File(s) Summary
CLI / Init
cmd/ingest/main.go
Initialize metrics earlier and pass logger + metrics into producer.NewRedpandaProducer(...) during producer construction.
Module Metadata
go.mod
Bumped Go version to 1.26.0 and added an indirect dependency github.com/kylelemons/godebug v1.1.0.
Metrics Infrastructure
internal/observability/metrics.go
Replaced ProduceErrors with ProduceSuccess, ProduceFail, and ProduceLatency histogram; updated metric names/help and initialization.
Producer Implementation
internal/producer/producer.go
Extended NewRedpandaProducer signature to accept logger and metrics; switched to ProduceAsync(...) (removed sync return), added async callback to record latency and success/fail metrics, enabled buffering/retries, increased linger, and flushes on Close().
Producer Tests
internal/producer/producer_test.go
Updated NewRedpandaProducer calls to include testLogger and *observability.IngestMetrics (nil); removed unreachable-broker sync test; adjusted test broker address and package-level logger.
HTTP Handler
internal/server/handler.go
Replaced synchronous Produce() with ProduceAsync() and removed inline sync error handling and immediate per-event EventsIngested metric increment; handler now increments local produced counter after queueing async production.

Sequence Diagram(s)

sequenceDiagram
    participant Handler as HTTP Handler
    participant Producer as RedpandaProducer
    participant Redpanda as Redpanda Broker
    participant Metrics as Observability

    Handler->>Producer: ProduceAsync(ctx, topic, key, event)
    alt Marshal error
        Producer->>Metrics: ProduceFail++ (marshal failure)
        Producer-->>Handler: returns immediately
    else Marshal success
        Producer->>Redpanda: enqueue ProduceMessages (async)
        Producer-->>Handler: returns immediately
    end

    Redpanda-->>Producer: async callback (ack or error)
    Producer->>Metrics: Observe ProduceLatency
    alt Success
        Producer->>Metrics: ProduceSuccess++
        Producer->>Metrics: EventsIngested += 1 (by site)
    else Failure
        Producer->>Metrics: ProduceFail++
        Producer->>Metrics: EventsRejected += 1 (by site)
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 Hop, hop — from sync to async I go,
metrics split like carrots row by row.
Latency counted, retries at play,
buffered messages hop on their way.
Flush the burrow, then off I bound — hooray!

📝 Coding Plan
  • Generate coding plan for human review comments

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@Ret2Hell
Ret2Hell merged commit 0ebc1cd into main Mar 19, 2026
4 checks passed
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