PCSM-273: Implement document level parallel replication#187
Merged
inelpandzic merged 19 commits intomainfrom Feb 24, 2026
Merged
PCSM-273: Implement document level parallel replication#187inelpandzic merged 19 commits intomainfrom
inelpandzic merged 19 commits intomainfrom
Conversation
dde6bcd to
41292b6
Compare
Instrument the replication dispatcher and per-worker flush loop with Prometheus metrics: event queue backpressure gauges, worker throughput counters, flush batch size and duration histograms, and transaction counters with size/duration histograms. Add log.String helper for string-typed log attributes. Change worker.id from int to string to avoid repeated strconv conversions in metric labels. Update the Grafana dashboard with a new Change Replication row (event queue sizes, worker throughput, flush batch size/duration p99, transactions) and Process panels (CPU, memory, file descriptors, GC pauses, heap breakdown). Queue size panels include a red threshold line at 5000 to indicate max capacity.
41292b6 to
6220ecd
Compare
56894ef to
1f4e820
Compare
chupe
reviewed
Feb 18, 2026
Comment on lines
98
to
99
| func New(scope string) Logger { | ||
| log := zerolog.Ctx(context.Background()).With().Logger() |
Collaborator
There was a problem hiding this comment.
QQ: I know it's not part of this PR but I'm just wondering why are we using a fresh context for each new logger?
571eb5d to
4f02fff
Compare
chupe
approved these changes
Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PCSM-273
Problem
Change replication processes events sequentially in a single goroutine — reading from the change stream, parsing BSON, and writing to the target all happen on the same thread. This becomes a bottleneck under high write throughput because bulk write latency on the target blocks the reader from consuming new events, increasing replication lag.
Additionally, all replication tuning parameters (worker count, queue sizes, bulk write batch size, change stream batch size) are hardcoded constants with no way to adjust them without rebuilding the binary.
Solution
Implement document-level parallel replication using a worker pool architecture. Events are read from the change stream by a single reader goroutine, then dispatched to workers based on a consistent hash of the document key. This preserves per-document ordering while parallelizing BSON parsing and bulk writes across multiple workers.
Key components:
The previously hardcoded
ReplQueueSizeconstant was split into two independent options since it controlled two architecturally different buffers: the dispatcher queue (between change stream reader and dispatcher) and the per-worker queue (between dispatcher and each worker).All replication tuning parameters are now configurable via env vars, CLI flags, and HTTP API, following the same pattern as existing clone options.
New configuration options
All options default to 0 which means "auto" (use the built-in default).