Skip to content

Conversation

untitaker
Copy link
Member

@untitaker untitaker commented Jun 25, 2025

Introduce sharding into the kafka producer, even with shards distributed across many brokers.

We could've had a different implementation where we have a ShardingProducer wrapping many Producers, but while this would avoid touching the most critical parts of the codebase, it would also mean a ton of additional code. I think it's cleaner to work towards a design where non-sharded topics are a special case of sharded topics.

ref RELAY-115

@@ -112,7 +112,6 @@ ed25519-dalek = "2.1.1"
enumset = "1.0.13"
flate2 = "1.0.35"
flume = { version = "0.11.1", default-features = false }
fnv = "1.0.7"
Copy link
Member Author

Choose a reason for hiding this comment

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

fnv was entirely unused

None => {
// fetch_add wraps on overflow
let count = self.round_robin_counter.fetch_add(1, Ordering::Relaxed);
count % self.topic_producers.len()
Copy link
Member Author

Choose a reason for hiding this comment

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

i think doing round-robin between shards in case of no key is probably cheaper than actually-random, wdyt

@untitaker untitaker marked this pull request as ready for review June 26, 2025 10:50
@untitaker untitaker requested a review from a team as a code owner June 26, 2025 10:50
Inner::ShardedSecondary(configs) => configs,
};

Ok(Self(configs))
Copy link
Member

Choose a reason for hiding this comment

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

We should guard somewhere against empty lists, can be here or in the config conversion to the Kafka* types.

@untitaker untitaker enabled auto-merge June 27, 2025 09:25
@untitaker untitaker added this pull request to the merge queue Jun 27, 2025
Merged via the queue into master with commit ccfc73d Jun 27, 2025
46 of 47 checks passed
@untitaker untitaker deleted the kafka-sharding branch June 27, 2025 10:25
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