Services

Accelerators

Resources

Company

Services

Accelerators

Resources

Company

Cover illustration for the case study: Kafka latency down 90% and throughput up 4× for a $300M SaaS platform

Case study

Caizin logo

/

Caizin

Kafka latency down 90% and throughput up 4× for a $300M SaaS platform

Kafka latency down 90% and throughput up 4× for a $300M SaaS platform

A $300M SaaS platform’s Kafka pipeline slowed to unusable during a tenant rollout. We found the bottleneck, raised throughput 4× and cut AWS costs by 40%.

A $300M SaaS platform’s Kafka pipeline slowed to unusable during a tenant rollout. We found the bottleneck, raised throughput 4× and cut AWS costs by 40%.

Cover illustration for the case study: Kafka latency down 90% and throughput up 4× for a $300M SaaS platform

The results

The results

40%

Lower infra cost

40%

Lower infra cost

3×

3×

More tenants supported

More tenants supported

20K

20K

Messages a second

Messages a second

01

The context

The client is a SaaS company in digital communications governance with about $300M ARR. Its event-driven architecture runs on Apache Kafka.

When one product rolled out to many new tenants, traffic doubled and the Kafka-based async pipeline slowed sharply. The slowdown spread to other systems and made the product unusable.

02

The challenge

An unexplained bottleneck: The event-driven pipeline had slowed down, and no one had pinned down why.

An unexplained bottleneck: The event-driven pipeline had slowed down, and no one had pinned down why.

An unexplained bottleneck: The event-driven pipeline had slowed down, and no one had pinned down why.

Costs tied to load: Infrastructure spend was set to climb with every increase in traffic.

Costs tied to load: Infrastructure spend was set to climb with every increase in traffic.

Costs tied to load: Infrastructure spend was set to climb with every increase in traffic.

High latency: Producer and consumer latency had jumped from under 5 ms to 30 ms, a 6× slowdown that delayed the whole event pipeline.

High latency: Producer and consumer latency had jumped from under 5 ms to 30 ms, a 6× slowdown that delayed the whole event pipeline.

High latency: Producer and consumer latency had jumped from under 5 ms to 30 ms, a 6× slowdown that delayed the whole event pipeline.

Low throughput: The system handled 5,000 messages a second, and the target was at least three times that.

Low throughput: The system handled 5,000 messages a second, and the target was at least three times that.

Low throughput: The system handled 5,000 messages a second, and the target was at least three times that.

03

The approach

Diagram: Asynchronous data processing pipeline architecture
Asynchronous data processing pipeline architecture

The backend architecture for the product consists of asynchronous data processing pipelines as shown in the diagram above. Kafka is used as a message broker and various workers act as producer and consumers across different topics and partitions.

The data pipeline consists of a Kafka producer that inserts 2000 messages per second into a Kafka topic. There are eight partitions in that topic and correspondingly, eight consumers (we call them workers in the diagram). Each of the workers perform the required business logic and finally generate 2 Million messages to be sent to new topic for further processing.

As the system experienced more scale (due to increase in tenants), the message volume increased in Kafka. This resulted in an increased latency in message processing going from 5 ms to 30 ms. At this point, we paused the further roll-out and started investigating this performance degradation.

After a lot of debugging and simulating the load in staging environment, we found the culprit.

The existing Kafka configuration resulted in excessive resource usage, increased latency, and inefficient data transfer. This inefficiency led to higher infrastructure costs and performance bottlenecks, affecting system scalability and reliability.

To fix this, we simulated the load on staging environment and narrowed down the problem to unoptimised Kafka configuration. In particular, the following three config options:

  • Linger.ms: (the maximum time to buffer messages before sending a batch to improve the throughput)

  • Batch.size: (the maximum size in bytes of a batch for each partition before it’s sent)

  • Compression.type: (the compression algorithm e.g., gzip, snappy, used to reduce message size before sending)

We wrote performance test suite to test various options for these config parameters to find out the optimal config value for our use case. We cover the details about this benchmarking process in a recent talk.

After analyzing the results, we identified the best configuration for the system as:

  • Batch Size: 65 KB

  • Linger Time: 500 milliseconds

  • Compression: Snappy

With these settings, Kafka efficiently grouped and compressed messages, reducing network calls and improving throughput while maintaining a reasonable CPU load. We deployed the new configuration in a staging environment, tested it under production-like traffic, and then rolled out in production.

With automated benchmarking, methodical testing, and data-driven tuning, we made Kafka faster and cheaper to run without losing scalability or reliability.

Diagram: Asynchronous data processing pipeline architecture
Asynchronous data processing pipeline architecture

The backend architecture for the product consists of asynchronous data processing pipelines as shown in the diagram above. Kafka is used as a message broker and various workers act as producer and consumers across different topics and partitions.

The data pipeline consists of a Kafka producer that inserts 2000 messages per second into a Kafka topic. There are eight partitions in that topic and correspondingly, eight consumers (we call them workers in the diagram). Each of the workers perform the required business logic and finally generate 2 Million messages to be sent to new topic for further processing.

As the system experienced more scale (due to increase in tenants), the message volume increased in Kafka. This resulted in an increased latency in message processing going from 5 ms to 30 ms. At this point, we paused the further roll-out and started investigating this performance degradation.

After a lot of debugging and simulating the load in staging environment, we found the culprit.

The existing Kafka configuration resulted in excessive resource usage, increased latency, and inefficient data transfer. This inefficiency led to higher infrastructure costs and performance bottlenecks, affecting system scalability and reliability.

To fix this, we simulated the load on staging environment and narrowed down the problem to unoptimised Kafka configuration. In particular, the following three config options:

  • Linger.ms: (the maximum time to buffer messages before sending a batch to improve the throughput)

  • Batch.size: (the maximum size in bytes of a batch for each partition before it’s sent)

  • Compression.type: (the compression algorithm e.g., gzip, snappy, used to reduce message size before sending)

We wrote performance test suite to test various options for these config parameters to find out the optimal config value for our use case. We cover the details about this benchmarking process in a recent talk.

After analyzing the results, we identified the best configuration for the system as:

  • Batch Size: 65 KB

  • Linger Time: 500 milliseconds

  • Compression: Snappy

With these settings, Kafka efficiently grouped and compressed messages, reducing network calls and improving throughput while maintaining a reasonable CPU load. We deployed the new configuration in a staging environment, tested it under production-like traffic, and then rolled out in production.

With automated benchmarking, methodical testing, and data-driven tuning, we made Kafka faster and cheaper to run without losing scalability or reliability.

04

The impact

Room to grow: The product team can roll out to 3× more tenants with better performance.

Room to grow: The product team can roll out to 3× more tenants with better performance.

Room to grow: The product team can roll out to 3× more tenants with better performance.

Room to grow: The product team can roll out to 3× more tenants with better performance.

40% lower cost: The hardware footprint shrank even as scale grew.

40% lower cost: The hardware footprint shrank even as scale grew.

40% lower cost: The hardware footprint shrank even as scale grew.

40% lower cost: The hardware footprint shrank even as scale grew.

90% lower latency: Producer and consumer latency fell from 30 ms to 2 ms.

90% lower latency: Producer and consumer latency fell from 30 ms to 2 ms.

90% lower latency: Producer and consumer latency fell from 30 ms to 2 ms.

90% lower latency: Producer and consumer latency fell from 30 ms to 2 ms.

4× throughput: Kafka now handles 20,000 messages a second, up from 5,000.

4× throughput: Kafka now handles 20,000 messages a second, up from 5,000.

4× throughput: Kafka now handles 20,000 messages a second, up from 5,000.

4× throughput: Kafka now handles 20,000 messages a second, up from 5,000.

Take this case study with you

A print-ready PDF of this story, to read later or share with your team.

Facing a similar problem?

Talk to the engineers who did this work at one2n.io/contact

Facing a similar problem?

Facing a similar problem?

Talk to the engineers who did this work. A 30-minute call, no slide decks, just your system and what we’d try first.

More case studies

Blogs.