How Zilla Works, Part 2: Extensibility Without Sacrificing Performance
Inside Zilla’s binary-native execution engine, from code-generated flyweights and shared-memory streams to protocol composition and predictable performance.



The Tension Between Performance and Extensibility
There is a fundamental tension in infrastructure software engineering between performance and extensibility.
Specialized systems can achieve exceptional performance by making assumptions about the workloads they handle. General-purpose systems, on the other hand, introduce abstractions to accommodate a broader range of workloads, often at the expense of efficiency.
This tension is particularly pronounced in network infrastructure, where every abstraction, memory allocation and data copy can introduce overhead on the critical path.
In the original How Zilla Works article, we explored how Zilla’s architecture was designed around three foundational principles: modularity, scalability and observability.
Since then, Zilla has extended well beyond its original Kafka-centric use cases to support native Kafka proxying, the Model Context Protocol (MCP), and large language model (LLM) connectivity. These capabilities have been introduced without replacing the underlying engine or introducing separate gateway stacks.
In this article, we’ll take a closer look at the engineering decisions that make this possible, from how Zilla represents data in memory to how it executes, composes and coordinates protocol processing.
Beyond Asynchronous I/O
High-performance Java networking frameworks such as Netty and Eclipse Vert.x have demonstrated that Java is capable of handling highly concurrent networking workloads efficiently. Rather than dedicating a thread to every connection, these frameworks use non-blocking I/O and event loops to multiplex work across a relatively small number of threads.
Vert.x extends this concept through its multi-reactor architecture, distributing event loops across available CPU cores while maintaining execution affinity for application handlers. Netty provides efficient networking primitives, pooled buffers and protocol codec pipelines. These are powerful foundations for building scalable network applications.
However, asynchronous I/O addresses only part of the performance challenge. Once data arrives from the network, it still needs to be decoded, inspected, routed, potentially transformed and encoded for transmission. Each stage introduces opportunities for memory allocation, data copying, synchronization and additional processing.
A networking framework provides developers with the primitives to implement these operations efficiently, but the architecture of the resulting application remains largely the responsibility of the developer. When designing Zilla, we wanted to address this problem at the engine level.
Rather than building a gateway on top of a general-purpose application framework, we designed a runtime specifically around the requirements of high-performance protocol processing. That meant rethinking not only how network events are scheduled, but also how data is represented, how processing stages communicate and how progress is coordinated across the entire protocol pipeline.
Binary-Native Execution
Consider what happens when a typical network application receives a binary message. The incoming bytes are decoded into an object representation. Application logic operates on those objects, potentially constructing additional intermediate objects along the way. When the message is forwarded, the resulting objects are encoded back into bytes.
This is a natural programming model, particularly in object-oriented languages such as Java. But for infrastructure that primarily moves data between systems, it raises an important question:
Why construct an object representation of data that already exists in memory?
A gateway frequently needs to inspect only a small subset of a message: a protocol header, a routing identifier, an authentication field or a topic name. The rest of the message may simply need to be forwarded. Constructing an intermediate object representation of the entire message introduces work that may not contribute to the outcome.

At sufficiently high message rates, even relatively small temporary allocations can generate substantial garbage collection pressure. For example, a system processing one million messages per second and allocating just 256 bytes of temporary objects per message would generate 256 MB of allocations every second, or approximately 922 GB of cumulative allocations per hour.
This is not the amount of memory resident at any given time. It is memory that the runtime must continually allocate and reclaim. Zilla approaches this differently. The binary representation of the data is itself the data structure.
Flyweights: A Typed View of Binary Data
Zilla makes extensive use of reusable flyweight objects that provide strongly typed access to existing regions of memory. Unlike a conventional Java object, a flyweight does not contain the values of the fields it represents. Instead, it maintains a reference to the underlying buffer and the location of the data within that buffer.
Consider a simplified binary protocol message containing a message type, a request identifier and a payload. A conventional representation might look like this:
An incoming message is decoded into an instance of this class, potentially allocating additional memory for the payload. A flyweight representation, by contrast, looks conceptually like this:
Rather than storing the message type or request identifier, the flyweight knows where those values reside in the buffer and how to interpret them. Accessing the request identifier becomes a direct memory read. If the request identifier is not needed, it does not need to be materialized. The payload can remain in its original binary representation.
Furthermore, the flyweight itself can be reused across messages by changing the region of memory it references.
The same flyweight instance can process millions of messages without allocating a new message object for each one. This is particularly valuable in a Java runtime, where reducing temporary allocations reduces garbage collection pressure and helps make latency more predictable.
The flyweight pattern is not unique to Zilla. Similar techniques are used extensively in latency-sensitive financial infrastructure and binary messaging technologies such as Simple Binary Encoding (SBE). What is distinctive about Zilla is the extent to which this approach permeates the entire protocol-processing architecture.
Flyweights are not an isolated optimization for a particular codec or protocol. They are a foundational mechanism for accessing both external binary protocol structures and the internal frames exchanged throughout the engine.
From Protocol Specifications to Executable Code
Manually implementing flyweight classes for every supported protocol would be both tedious and error-prone. Binary protocols introduce considerable complexity: fixed- and variable-length fields, nested structures and arrays, different byte orders, optional fields and message variants, buffer boundaries and offset calculations, and multiple versions of protocol messages.
Kafka alone defines dozens of protocol interactions, many with multiple encoding versions. To address this complexity, Zilla includes its own build-time code-generation tooling. Binary structures are defined declaratively using an Interface Definition Language (IDL). A simplified specification might look like this:
During the Maven build lifecycle, Zilla’s flyweight-maven-plugin processes these .idl specifications and generates the corresponding strongly typed Java flyweight classes. These generated classes include mechanisms for reading existing binary structures and constructing new ones directly in destination buffers.

Conceptually, encoding a message becomes:
Rather than constructing an intermediate request object and subsequently serializing it, the builder writes the binary representation directly into memory. This shifts much of the complexity of binary encoding and decoding from runtime implementation to build-time code generation.
Protocol developers can concentrate on protocol semantics, state machines and interactions rather than repeatedly implementing the mechanics of accessing binary structures. The generated APIs also retain Java’s strong typing while providing direct access to the underlying data.
In effect, Zilla’s flyweight compiler allows us to combine the maintainability of declarative binary specifications with many of the performance characteristics of manually optimized binary processing. More importantly, the same tooling is available to each new protocol implementation. Performance is not an optimization that must be independently rediscovered every time Zilla adds support for another protocol.
A Protocol for Implementing Protocols
Efficient binary processing solves only part of the problem. A multi-protocol gateway also needs a mechanism for composing different protocol implementations without introducing unnecessary intermediary processing or tightly coupling those implementations together. Zilla achieves this through a common internal streaming protocol.
Regardless of the external protocol being processed, communication between Zilla’s protocol bindings follows a consistent streaming model. Each stream is established, progresses and terminates through a defined set of binary frames.

Each bidirectional interaction is represented through streams with independently managed lifetimes and flow control. This internal abstraction is sufficiently general to represent a wide range of external protocol interactions, from a TCP connection to an HTTP request-response exchange, an MQTT subscription or a Kafka fetch stream.
Protocol-specific information is represented through typed extensions to these frames. An HTTP stream might carry HTTP headers in its BEGIN extension, while a Kafka stream might carry topic and partition information in its corresponding extension. The semantics remain specific to each protocol, but the mechanics of communication remain consistent.
This distinction is important. Zilla does not normalize every protocol into a lowest-common-denominator message format. Instead, it provides a common model for how protocol-specific interactions progress.
In effect, Zilla defines a protocol for implementing protocols. This creates a stable architectural boundary between individual protocol implementations and the engine responsible for executing them. It is also what allows protocol mappings to concentrate on translating metadata, semantics and stream lifetimes rather than reinventing communication, scheduling and flow-control mechanisms.
Shared Memory as the Communication Fabric
In conventional application architectures, processing stages typically communicate through method calls, callbacks, asynchronous events or message buses. Each of these approaches has different performance and modularity characteristics. Zilla’s protocol bindings communicate through binary stream frames in shared memory.
Each engine worker maintains a memory-mapped circular buffer representing its work queue. When a binding processes an incoming frame, it may produce another frame representing progress on a different stream. Under normal circumstances, this frame is written to the same worker’s queue. The receiving binding then processes the frame using the same flyweight-based access mechanisms described earlier.
When communication across workers is necessary, such as in certain fan-in and fan-out scenarios, lock-free data structures and ordered memory operations minimize the coordination required between CPU cores.

This architecture creates a consistent communication mechanism both within and across engine workers. It also provides a useful separation between the implementation of a protocol and the scheduling of its execution. An HTTP binding does not need to know the implementation details of a downstream Kafka binding. Both interact through the engine’s streaming contract.
This allows protocol bindings to remain modular without introducing a general-purpose object messaging layer between them. Memory-mapped buffers and flyweights play complementary roles in this architecture. Memory mapping provides a mechanism for accessing memory regions directly, while flyweights provide structured, strongly typed access to the binary data within those regions.
Neither technique alone guarantees that data is never copied. TLS processing, encryption, protocol transformations and operating system interactions can still require additional writes or copies. The objective is to eliminate unnecessary intermediate representations and memory movement wherever possible.
Backpressure as an Architectural Invariant
One of the most difficult problems in streaming systems is managing differences in the rate at which producers generate data and consumers process it. Consider a gateway consuming messages from Kafka and delivering them to a browser over Server-Sent Events. Kafka may be capable of supplying data much faster than the browser or its network connection can consume it.
Without effective backpressure, the gateway must continuously buffer incoming data, increasing memory consumption and potentially introducing instability. Reactive frameworks recognize this problem. Vert.x, for example, provides ReadStream and WriteStream abstractions that allow applications to regulate data flow through mechanisms such as pausing, requesting data and monitoring write queues.
These are useful primitives for implementing backpressure. Zilla takes the concept further by embedding flow control directly into the internal communication contract between bindings. The receiving side of each stream communicates its available capacity to the sending side through WINDOW frames. The sender can only make progress within the capacity granted by the receiver.
Because this mechanism is part of the internal streaming protocol, it applies consistently across binding boundaries. A slow downstream connection can therefore constrain upstream progress through multiple protocol-processing stages, rather than requiring every integration to introduce its own independent buffering strategy.
This is especially important when the protocols involved have fundamentally different communication models. An HTTP/2 connection might multiplex many concurrent request-response exchanges. An MQTT connection might represent multiple subscriptions. A Kafka consumer might aggregate data from many topic partitions.
These differences can be represented through streams with independent flow control, while the underlying mechanism for regulating progress remains consistent. Backpressure becomes an architectural invariant rather than an application-level optimization. It is one of the mechanisms that enables Zilla to handle long-lived connections, large payloads and heterogeneous streaming workloads while controlling unnecessary buffering.
Keeping Execution Local
Modern CPUs are designed to achieve high aggregate performance through parallel execution across multiple cores. However, adding more cores does not automatically translate into proportional increases in application performance. Coordination between cores introduces costs associated with synchronization, memory visibility and CPU cache coherence.
Both Vert.x and Zilla address this challenge through execution affinity. Vert.x generally associates application handlers with particular event loops, simplifying concurrency management and reducing the need for synchronization. Zilla applies a similar principle to its protocol-processing architecture.
Each engine worker executes in a single-threaded context and maintains its own instances of the relevant engine modules. When a client establishes a connection, its processing is normally assigned to a worker that continues to handle the associated protocol pipeline. This allows the majority of processing to take place without coordination between workers.
The architecture is shared-nothing where practical, with explicit mechanisms for communication when workloads require it. Certain workloads, such as distributing the same Kafka data to clients connected to different workers, naturally involve cross-worker interactions.
Rather than introducing shared mutable application state or relying on conventional locking for these interactions, Zilla uses its internal streaming mechanism and lock-free data structures. This helps preserve the performance characteristics of individual workers as additional CPU cores become available.
The principle of worker affinity is well established in high-performance systems. What matters is how consistently it is applied throughout the architecture, from network I/O to protocol processing, routing and data distribution.
Scaling the Kafka Cache Across Cores
Fan-out and fan-in are among the most demanding patterns a gateway faces when it exposes Kafka to clients that don’t speak the Kafka protocol. One topic partition may need to reach thousands of SSE, MQTT or HTTP clients across every engine worker, and those same clients may all be producing too. Zilla’s Kafka cache handles both directions. In earlier releases, though, hydrating the cache from Kafka ran on a single core, which limited how much additional cores could help.
The cache is now organized as a full mesh between cache clients and cache servers across all engine workers. Each topic partition is assigned by hash to exactly one cache server worker, which owns that partition’s communication with Kafka. For fetch, the owning worker is the only writer of the partition’s memory-mapped segments, and cache clients on any worker read from them in place. Produce works the same way in reverse: cache clients write produced messages into segments, and the owning worker reads them and sends them to Kafka. In both directions, only lightweight notifications cross between workers. The messages themselves are never copied from one worker to another.
Notifications carry the partition’s high water mark, so they coalesce naturally when a cache client is busy. Each consumer also tracks its own progress, so a slow consumer never holds back the writer. As a result, coordination between cores depends on how often notifications are sent, not on message size or the number of clients. In our internal testing of MQTT workloads mapped to Kafka, doubling the workload against double the cores doubled the throughput Zilla sustains.
Like Kafka itself, the cache treats the partition as the unit of parallelism. The design also leaves room for automatic rebalancing, migrating partitions that compete with a hot partition to other workers. And because every binding reaches the cache through the same internal streaming contract, SSE, MQTT and HTTP clients all benefit without any changes.
Short Execution Stacks
Another less visible consideration in the design of Zilla is the structure of its execution stacks. A conventional protocol codec pipeline may involve a sequence of nested handler invocations. A network event triggers a handler, which invokes a decoder, which invokes another handler, which may invoke application logic and subsequently an encoder.
This is a flexible programming model. However, increasingly deep invocation stacks can complicate the work of the JVM’s just-in-time (JIT) compiler. In particular, they can make it more difficult for the JVM to apply optimizations such as method inlining and escape analysis.
Based on our previous experience implementing high-performance protocol servers, we wanted to avoid placing unnecessary constraints on these optimizations. Zilla’s frame-based architecture naturally creates shorter execution boundaries. An engine worker processes a network event or an internal stream frame, potentially writes another frame to a work queue, and then unwinds its execution stack. The next unit of work is subsequently processed by the worker.
This does introduce the cost of writing and reading internal frames. A direct method invocation may be cheaper when considered in isolation. But the architecture is designed around the behavior of the complete processing pipeline rather than the cost of an individual invocation.
It provides explicit scheduling boundaries, reduces dependence on deeply nested protocol-processing calls, and creates opportunities for the JVM to optimize frequently executed code. Combined with reusable flyweights, this allows Zilla to pursue predictable execution within a managed Java runtime without relying exclusively on the JVM to eliminate temporary allocations.
Designing for Different Workloads
A gateway cannot assume that every workload consists of messages of the same size, connections of the same duration or consumers operating at the same rate. Two workloads with identical aggregate throughput can have very different performance characteristics. One might consist of thousands of clients transferring small amounts of data. Another might consist of a few clients transferring large amounts of data. A third might combine both, while continuously establishing new encrypted connections.
Zilla’s architecture isolates several of these workload-specific concerns. Network communication with the operating system is concentrated within the TCP binding, allowing subsequent processing stages to operate on the common internal stream abstraction.
Computationally expensive portions of TLS handshakes can be offloaded from the primary engine worker so that established connections can continue making progress. Large transfers can be fragmented into smaller internal data frames, allowing other streams to make progress between fragments.
This last consideration is particularly important for maintaining responsiveness when different workloads share the same gateway. A large data transfer should not unnecessarily prevent a small, latency-sensitive message from progressing simply because both are assigned to the same worker.
These mechanisms address different problems, but they share a common architectural objective: preventing one interaction from unnecessarily interfering with the progress of another.
Observability as a Property of Execution
An interesting consequence of Zilla’s internal communication model is that protocol processing leaves behind a structured representation of its own execution. Every engine worker maintains a circular buffer containing the binary stream frames used to communicate between processing stages.
These frames are not additional diagnostic messages generated solely for logging purposes. They are part of the normal execution of the engine. Observing these frames provides a view into the interactions occurring within and across workers, including stream establishment, data transfer, flow control and termination.
There is an analogy to network packet capture, except that the communication being observed is internal to the gateway. In traditional application architectures, obtaining this degree of visibility might require additional instrumentation or increased logging verbosity, potentially affecting the behavior being investigated.
Zilla’s communication architecture provides an additional diagnostic surface that can be inspected alongside its conventional metrics, log events and distributed tracing integrations. This can be particularly useful when investigating protocol translation behavior, stalled streams or unexpected backpressure.
The underlying circular buffers have finite capacity, so this should not be confused with permanent execution recording or a complete historical audit trail. Nevertheless, the ability to observe internal interactions without first introducing a separate representation of those interactions is a useful consequence of the architecture.
Observability is not exclusively an instrumentation layer added on top of the runtime. It is also a property of how the runtime executes.
How Zilla Differs from General-Purpose Reactive Frameworks
It is entirely possible to build a highly efficient gateway using a general-purpose networking framework such as Netty or Vert.x. These projects provide sophisticated networking and concurrency mechanisms, and many of the principles discussed here are shared across high-performance infrastructure. The distinction lies primarily in the level at which architectural decisions are made.
A developer building a multi-protocol gateway on top of Vert.x could implement many of the same architectural mechanisms. However, reproducing Zilla’s architecture would require implementing a substantial set of additional infrastructure:
- A common internal streaming protocol.
- Strongly typed binary data representations and code generation.
- Memory-efficient communication between protocol stages.
- Consistent flow control across protocol boundaries.
- Composable protocol-processing modules.
- Declarative routing and configuration.
- Reusable security, governance and observability mechanisms.
At that point, the resulting application would itself resemble a specialized protocol runtime. This does not make a specialized runtime inherently faster than every application built using a general-purpose framework. General-purpose frameworks also have advantages, including mature networking ecosystems, native transport implementations and greater freedom in application programming models.
The trade-off is that Zilla deliberately constrains how protocol implementations interact in exchange for greater architectural control over memory management, scheduling and data movement. Rather than providing only the primitives with which efficient protocol infrastructure can be built, Zilla provides a common architecture within which that infrastructure executes.
Extensibility Without Architectural Fragmentation
The value of these architectural decisions becomes more apparent as Zilla supports additional protocols. When we initially focused on integrating web, mobile and IoT clients with Apache Kafka, the engine was designed to support a much broader set of communication patterns than Kafka alone.
The same architectural foundations now underpin native Kafka proxying, MQTT connectivity, HTTP and Server-Sent Events, MCP and LLM connectivity. Each new capability requires its own protocol-specific implementation. MCP and LLM interactions have different semantics from Kafka or MQTT. They introduce different requirements around metadata, routing, authorization and message transformations.
But they do not require an entirely different execution architecture. The underlying engine continues to provide the same mechanisms for:
- Binary data access and encoding.
- Stream lifecycle management.
- Incremental data processing.
- Flow control and backpressure.
- Multicore execution.
- Protocol composition.
- Security and observability integrations.

This is particularly relevant for emerging AI infrastructure. Although the applications are different, many of the underlying networking challenges are familiar: long-lived connections, incremental responses, variable message sizes, multiplexed interactions and downstream consumers operating at different speeds.
LLM token streaming is, from an infrastructure perspective, another streaming workload. The engine does not need to be redesigned around it. This is where the distinction between a collection of gateway implementations and a common gateway engine becomes important.
Adding functionality does not have to mean adding another proxy stack, another concurrency model or another mechanism for managing memory and flow control. Instead, the engineering investments made in the underlying runtime can continue to benefit new protocol implementations.
From Architecture to Measurable Performance
Architectural decisions are ultimately meaningful only if they translate into measurable outcomes. Over the course of the Zilla benchmark series, we have examined the performance characteristics of Zilla across different workloads, including native Kafka proxying, data encryption and LLM gateway processing.
These workloads exercise very different aspects of the engine. Yet they benefit from the same underlying approach to minimizing intermediary processing, memory allocation and coordination.
Our LLM gateway benchmarks, for example, demonstrated sub-millisecond median gateway overhead under the tested conditions. For us, the significance of these results extends beyond the absolute latency numbers. They demonstrate that the architectural principles originally applied to Kafka and real-time event distribution can also be applied to a substantially different category of infrastructure.
As we continue to evolve Zilla, we are interested in examining additional characteristics of the engine, including:
- Allocated bytes per processed message.
- Garbage collection behavior under sustained load.
- Throughput per CPU core.
- Scalability as additional cores become available.
- Tail latency across heterogeneous workloads.
- Memory consumption under sustained backpressure.
- Incremental overhead introduced by additional protocol-processing stages.
These measurements help distinguish an architecture that performs well under a particular benchmark from one that is designed to retain its performance characteristics across different workloads.
Looking Ahead
The individual techniques described in this article are not necessarily new. Non-blocking I/O, flyweights, shared-memory communication, lock-free data structures, worker affinity and credit-based flow control all have established histories in high-performance computing and networking.
The interesting engineering challenge is bringing these techniques together into an extensible architecture without having to compromise the abstractions that make extensibility possible. For Zilla, this means treating performance not as an optimization applied independently to each protocol, but as a property of the engine on which those protocols are implemented.
It means preserving the ability to introduce new capabilities without introducing new execution architectures. And it means building infrastructure that can adapt as the protocols, workloads and applications around it continue to evolve.
Today, Zilla supports workloads spanning real-time data distribution, event-driven applications and enterprise AI connectivity. Tomorrow, those workloads and their underlying protocols will undoubtedly evolve again. The objective remains the same:
Extensibility without sacrificing performance.
Explore the Zilla project on GitHub, learn more in the Zilla documentation, or join the Aklivity community.
Related Resources


Ready to Get Started?
Get started on your own or request a demo with one of our data management experts.
Explore pricing
Straightforward, usage-based pricing with no per-connection surprises — start free and scale when you are ready.
Join the Community
Trade notes with the engineers running Zilla in production, and get help from the team in Slack or Discord.





