blog by OSO

Protecting Kafka Cluster: Kafka before client – Putting the guardrails in place for Apache Kafka clients

Sion Smith
Sion Smith 23 June 2023
OSO article card for protecting a Kafka cluster with guardrails for Kafka clients, white title text on a navy panel and a lime Blogs label.

Updated November 2026: We have restyled this June 2023 post, added a comparison of where Kafka guardrails can be enforced (client interceptors, broker policies and quotas, and proxies), and replaced outdated and broken links.

In this article, we discuss the importance of protecting a Kafka cluster from bad actors and the benefits it brings to your organisation. We explore the three stages of safeguarding, the challenges in each stage and the ultimate goal of proactive automation. We also examine the different approaches to implementing safeguarding measures and the role they play in a resilient Kafka infrastructure.

Why is protecting a Kafka cluster important?

There are several reasons why safeguarding a Kafka cluster is crucial. Firstly, it helps minimise outages and reduces the associated costs. Outages can be expensive, both in monetary losses and in the impact on your organisation’s reputation. By implementing protective measures, you can mitigate the risk of downtime and keep your Kafka infrastructure running smoothly.

Secondly, safeguarding Kafka allows you to respond gracefully to change. In a complex organisation with multiple domains and conflicting priorities, the ability to adapt quickly and limit the impact of changes is essential. By reducing friction and enabling efficient collaboration, safeguarding promotes velocity and helps you achieve your goals faster.

What does safeguarding Kafka mean?

Safeguarding is the practice of protecting your data and infrastructure from intentional and unintentional threats, both internal and external. It involves implementing measures to ensure the security and resilience of your Kafka system. Safeguarding sits at the intersection of data governance and technical best practice, giving you an efficient and reliable system for your Kafka cluster.

After speaking with numerous customers, we have identified three main stages that organisations tend to be in when it comes to safeguarding their Kafka clusters. These stages complement each other and represent different levels of maturity in safeguarding practice.

What are the three stages of safeguarding Kafka clusters?

StageHow rules are appliedMain weakness
1. Safeguarding by habitDocumented best practices, wikis and production readiness checksEnforcement depends on people; checks go stale
2. Reactive automationMetrics, thresholds and alerts after something goes wrongTemporary fixes become permanent technical debt
3. Proactive automationChecks applied automatically at the client boundaryNeeds an enforcement point every client must pass through

Stage one: safeguarding by habit

In this stage, safeguarding measures are loosely defined and negotiable. Best practices and efficiency goals are documented in Google Docs or wikis. The business generally agrees to abide by these rules, but enforcement is limited to human interaction. This stage often involves production readiness checks, which suffer from relevance and timeliness issues.

Stage two: reactive automation

In this stage, safeguarding measures are implemented through reactive automation. The Kafka cluster generates metrics and monitoring information, which are used to set thresholds and alerts. When issues arise, the right people are notified and temporary solutions are put in place. However, these temporary solutions can become permanent, resulting in technical debt and a decrease in velocity. Our guide to Kafka monitoring tools covers the metrics most teams start with.

Stage three: proactive automation (the gold standard)

The ultimate goal of safeguarding is proactive automation. This stage applies checks and balances at the earliest possible point in the Kafka ecosystem, which is the client. Proactive automation prevents common mistakes automatically and alerts the right people about more complex issues. By enforcing safeguarding measures at the earliest point, you get efficiency and best practice throughout your Kafka infrastructure.

Why does proactive safeguarding matter?

Proactive safeguarding not only prevents outages but also resets the perception of efficiency and best practice within your Kafka infrastructure. It ensures that common mistakes are automatically addressed and more complex issues are stopped before they cause harm. This encourages developers and application teams to think about the overall efficiency of the system and to build best practices into their software.

How do inter-domain contracts enforce safeguarding?

Proactive safeguarding is achieved by enforcing inter-domain contracts. These contracts are, in effect, the interceptor controls that ensure safeguarding rules are followed, for example limits on topic configuration, message size or client settings agreed between the platform team and each domain. With these controls in place, your organisation can react gracefully to change and achieve broader technical goals without lengthy meetings and policies.

How can you implement Kafka guardrails?

When it comes to implementing safeguarding measures, there are different approaches to consider.

ApproachExamples in Apache KafkaStrengthsLimitations
Client pluginsProducer and consumer interceptors (interceptor.classes), shared client librariesClose to the application; rich contextAt least one plugin per application; clients can bypass them
Broker plugins and settingscreate.topic.policy.class.name, alter.config.policy.class.name, quotas, ACLsEnforced centrally on the clusterLimited hooks; custom policies run inside the brokers
ProxyA Kafka-protocol proxy such as the open-source KroxyliciousEvery client passes through it; rules change without client releasesAnother component to run; building one yourself is a large investment

One option is to use client plugins, which require at least one plugin per application. However, this approach is difficult to manage and doesn’t fully address the problem, because bad actors can bypass the plugin and go directly to Kafka.

Another option is to use broker plugins, such as topic creation and configuration policies, together with quotas and ACLs. These are valuable, but they have their own limitations and constraints: they only cover the hooks Kafka exposes, and custom code runs inside your brokers.

The preferred solution is a proxy that sits in the middle and speaks the Kafka wire protocol. However, building a proxy that meets these requirements yourself is a significant technical investment.

A more practical approach is to rely on a platform that takes care of the low-level production aspects and lets you implement safeguarding rules. This platform provides the infrastructure and automation needed to enforce safeguarding measures effectively. For the access-control side, see our guide on how to secure your Apache Kafka cluster.

What is the takeaway for protecting your Kafka cluster?

Safeguarding your Apache Kafka cluster is essential for protecting your data and infrastructure from threats. It helps minimise outages, enables efficient collaboration and promotes velocity. Remember that proactive safeguarding is not a replacement for data governance and best practice policies, but a way to enforce those policies in the right place. It also reduces reliance on reactive fixes for common issues, so you can focus on more complex problems.

To achieve proactive safeguarding, implement measures at the earliest possible point in the Kafka ecosystem, which is the client. That way you automatically prevent common mistakes and alert the right people about more complex issues. Client plugins, broker plugins and proxies are all options, but each has its limitations; a platform that handles the low-level production aspects is usually the most practical route.

If you are offering Kafka to many teams, watch our Kafka Summit talk on offering Kafka as a service, read about self-service Kafka operations, or talk to OSO’s Kafka engineers about putting guardrails in place.

Key takeaway: Protect your Kafka cluster at the client boundary. Habits and alerts help, but proactive guardrails, ideally enforced by a Kafka-protocol proxy every client passes through, stop bad requests before they reach the brokers.

Frequently asked questions

What does protecting a Kafka cluster mean?

It means stopping client mistakes and bad actors from harming the cluster, for example oversized messages, badly configured topics or runaway clients. It covers security controls such as authentication and ACLs as well as guardrails on how clients use Kafka.

What are Kafka guardrails?

Rules that are enforced automatically when clients use Kafka, such as limits on topic partitions, replication factor, message size or client configuration. They turn documented best practice into checks that cannot be skipped.

Where can Kafka guardrails be enforced?

In client interceptors or shared libraries, in broker-side policies, quotas and ACLs, or in a proxy that speaks the Kafka protocol and sits between clients and brokers. A proxy is the only option every client has to pass through without changing each application.

What are the three stages of safeguarding Kafka?

Safeguarding by habit, where rules live in documents and reviews; reactive automation, where metrics and alerts flag problems after they happen; and proactive automation, where checks are enforced automatically at the client boundary.

Can Kafka brokers enforce topic policies on their own?

Partly. Kafka lets you plug in topic creation and configuration policies and set client quotas, but these cover a limited set of hooks and custom policy code runs inside the brokers.

Put guardrails on your Kafka

Talk to OSO's Kafka engineers about protecting your Kafka cluster with automated guardrails, policies and self-service for every team.

CONTACT US
OSO
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.