↓Skip to main content
Case Study

Kubernetes Operator for Distributed MQTT Broker Clusters

ContextMQTT broker, 40-node clusters
RoleSenior Software Engineer — v2 architecture, prototype, test suite
Outcome90% test coverage; 10-node cluster tests with node loss

Context & Ownership #

The business needed stable 40-node MQTT broker clusters that customers could run and scale on any Kubernetes cluster. Supporting 40-node clusters and frequent changes safely called for a new, modular design.

I designed the modular architecture and built the v2 prototype and its test framework. Another Java engineer and I then built the v2 operator and Helm chart. The broker core team owned the broker features the operator depended on.

v2 operator and cluster architecture

Constraints #

The broker has strict rules for adding and removing nodes, and standard Kubernetes resources cannot enforce them. Two problems ruled out fixing v1 step by step:

  • Untestable operator. The core logic was tightly coupled and could not run in isolation.
  • Fragile Helm chart. The chart took complete Kubernetes manifests as values, such as the full load balancer Service YAML. Users had to know Kubernetes internals, and every change risked breaking a deployment.

One dependency applied to any version: the broker lacked the liveness, readiness, and start/stop interfaces an operator needs.

Trade-offs & Alternatives #

Option EvaluatedPrimary AdvantageRejection Reason / Accepted Risk
Patch v1 operator and chartKeeps v1 APIs intactUntestable coupling and raw YAML templating blocked safe fixes
Helm-only without custom operatorNo controller code to maintainPod ordering, preStop hooks, and PodDisruptionBudgets cannot check broker cluster state before a node joins or leaves
Modular v2 operator + abstracted Helm chartTestable core logic and no raw YAMLChosen — required breaking v1 APIs and aligning with the broker team

Execution & Alignment #

The prototype used Java, the Quarkus Operator SDK, and Gradle. The company was a Java shop, so the team could support the operator without adding a language. The Java Operator SDK separates the operator into reconcilers and dependent resources, so we could test scaling rules and failure handling in isolation, without a full cluster.

After the prototype, I added the test framework. Integration tests use Testcontainers to start a k3s Kubernetes cluster, then run the operator and the broker nodes as pods inside it. The operator targets 40-node clusters; the integration tests ran 10-node clusters.

We turned the prototype into the v2 operator and rewrote the Helm chart. The new chart asks only for what the user cares about, such as how to expose the broker and on which ports, and generates the Kubernetes resources from that. Shipping as v2 let us break the coupled v1 interfaces. We kept v1 supported for several years, recommended that customers move to v2, and helped them migrate on a best-effort basis.

We brought the missing broker interfaces to the broker core team, and they implemented them.

Outcome #

Test coverage reached 90%, enforced as a CI gate. Unit tests run in CI on every build and integration tests on every merge, and the framework made new tests cheap to add. The tests check for message loss when adding or removing a broker, and simulate stateful failures such as node loss and split brain.

What I would do from the start next time:

  • Design the Helm chart around what users configure, not around raw Kubernetes manifests.
  • Treat integration tests as equal to unit tests from the first commit. For containerized applications, much of the behavior only shows up when the containers run.
  • Require liveness, readiness, and start/stop interfaces from the application before writing the operator.
Company and internal names omitted.