Skip to content

Conversation

@nischitpra
Copy link
Collaborator

@nischitpra nischitpra commented Sep 4, 2025

Summary by CodeRabbit

  • New Features
    • Support for larger Kafka messages (up to 100 MB), enabling handling of bigger payloads without fragmentation.
  • Bug Fixes
    • More robust Kafka publishing: per-record error handling, aggregated failures, and safe transaction aborts to prevent partial writes.
  • Chores
    • Updated local deployment configuration to align broker limits with larger message support.

@coderabbitai
Copy link

coderabbitai bot commented Sep 4, 2025

Walkthrough

Kafka broker limits increased to 100MB via docker-compose. Producer batch max bytes raised to 100MB in publisher initialization. Kafka publisher’s transactional publish flow updated to use per-record async callbacks, collect produce errors with synchronization, wait for callbacks post-flush, and abort or commit the transaction accordingly.

Changes

Cohort / File(s) Summary
Docker Compose: Kafka broker config
docker-compose.yml
Added KAFKA_MESSAGE_MAX_BYTES=104857600 and KAFKA_REPLICA_FETCH_MAX_BYTES=104857600 to the broker service environment.
Producer config: batch size
internal/publisher/publisher.go
Increased kgo.ProducerBatchMaxBytes from 16MB to 100MB (100 * 1024 * 1024).
Kafka publisher transactional flow
internal/storage/kafka_publisher.go
Increased producer batch size to 100MB. Switched to per-record async callbacks capturing errors with mutex-protected slice and WaitGroup. After flush, waits for all callbacks; aborts transaction on any produce/flush error (TryAbort) or commits if none; returns aggregated error on failures.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor C as Caller
  participant KP as KafkaPublisher
  participant P as Producer (kgo)
  participant K as Kafka

  Note over KP: Batch size set to 100MB

  C->>KP: publishMessages(records)
  activate KP

  loop For each record
    KP->>P: Produce(record, callback)
    note right of P: Callback captures per-record error<br/>and appends to shared errors slice
    P-->>KP: async callback(err)
  end

  KP->>P: Flush()
  alt Flush fails
    KP->>P: EndTransaction(TryAbort)
    KP-->>C: error (flush failed)
  else Flush succeeds
    KP->>KP: Wait for all callbacks
    alt Any produce error captured
      KP->>P: EndTransaction(TryAbort)
      KP-->>C: aggregated produce error(s)
    else No produce errors
      KP->>P: EndTransaction(Commit)
      KP-->>C: success
    end
  end
  deactivate KP
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch np/debug_84532

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/publisher/publisher.go (1)

68-72: Make ProducerBatchMaxBytes configurable via Publisher config

  • Replace the hard-coded 100 * 1024 * 1024 in kgo.ProducerBatchMaxBytes (internal/publisher/publisher.go:68) with a new Publisher.MaxBatchBytes field wired through your config. Ensure brokers’ socket.request.max.bytes, each topic’s max.message.bytes, and consumers’ max.partition.fetch.bytes (and fetch.max.bytes) are ≥ this value.

(Optional)

  • Switch to kgo.ZstdCompression() for better wire compression.
  • Add kgo.ProduceRequestTimeout(30 * time.Second) and kgo.RequestRetries(5) for increased resiliency.
🧹 Nitpick comments (3)
internal/storage/kafka_publisher.go (3)

72-79: 100MB batches: align with broker/topic/consumer limits and consider configurability.

The bump is fine, but ensure:

  • Broker socket.request.max.bytes > 100MB and topic max.message.bytes ≥ 100MB.
  • Consumers’ max.partition.fetch.bytes ≥ 100MB.
  • Optionally make this tunable via config to avoid per-env edits.

164-168: Good: per-record error collection with proper synchronization.

Pre-allocate and prefer errors.Join for aggregation to keep error type semantics.

- // Track if any produce errors occur
- var produceErrors []error
+ // Track if any produce errors occur
+ produceErrors := make([]error, 0, 8) // small cap to reduce reallocs
  var produceErrorsMu sync.Mutex
  var wg sync.WaitGroup

189-200: Join errors and log abort failures for better debuggability.

  • Prefer errors.Join(produceErrors...) so callers can inspect individual causes.
  • If EndTransaction (abort) fails, log it; currently ignored.
- hasErrors := len(produceErrors) > 0
- if hasErrors {
-   // Abort the transaction if any produce errors occurred
-   p.client.EndTransaction(ctx, kgo.TryAbort)
-   return fmt.Errorf("transaction aborted due to produce errors: %v", produceErrors)
- }
+ if len(produceErrors) > 0 {
+   if err := p.client.EndTransaction(ctx, kgo.TryAbort); err != nil {
+     log.Error().Err(err).Msg("failed to abort transaction after produce errors")
+   }
+   return errors.Join(produceErrors...)
+ }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 63e4887 and 965cb46.

📒 Files selected for processing (3)
  • docker-compose.yml (1 hunks)
  • internal/publisher/publisher.go (1 hunks)
  • internal/storage/kafka_publisher.go (3 hunks)
🔇 Additional comments (2)
docker-compose.yml (1)

90-91: Cannot verify topic configs in this environment; please run the provided kafka-topics/kafka-configs commands on a host with the Kafka CLI installed to confirm per-topic max.message.bytes settings and apply updates as needed.

internal/storage/kafka_publisher.go (1)

171-180: LGTM: callback-based error capture inside a transaction.

The WaitGroup usage is correct (Add before Produce) and thread-safe error capture is solid.

@nischitpra nischitpra merged commit bd3eca1 into main Sep 4, 2025
5 checks passed
@nischitpra nischitpra deleted the np/debug_84532 branch September 4, 2025 14:04
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.

2 participants