You can craft custom experiences, one capability at a time. Some architectural styles are particularly well suited for some capabilities, and the microkernel architecture is the world champion at customization. But it’s also useful for a bewildering range of applications. Once you understand this architectural style, you’ll start seeing it everywhere!
Let’s dig into an architecture that lets your users have it their way.
The benefits of Going Green
What does everyone have lying around? Old electronics! Going Green is a fast-moving startup that plans to capitalize on the market for buying and recycling old cell phones, music players, and other small electronics.
After analyzing the architectural characteristics required, the architects have designed a three-part system, and each part of which needs different capabilities. They’d like your help. Ready? Here’s the system so far:
Brain Power
Based on what we know about Going Green’s business model and the corresponding separation of responsibilities in its system, would it be easier for this company to build a monolithic or a distributed architecture? Why?
BE the architect
Architects just can’t stop analyzing stuff. Can you determine three important architectural characteristics for each of the three services in the new Going Green architecture?
Solution in “BE the architect Solution”
Cubicle conversation
Mara: We need to split up the architecture work for the Going Green application. Mara, you and Alex should work on the device assessment service.
Alex: Great! That’s the service that assesses the devices users send us to determine value, right? Seems like one of the more interesting parts of the application.
Sam: How often will we need to add new device configurations to the assessment service?
Mara: At least a few times a month, sometimes even a few times a week. This is especially important, because how fast we can update the device assessment service directly affects the company’s profitability.
Sam: Why such a direct connection?
Mara: Going Green makes a profit when it resells the highest-value electronics it receives. Generally, newer devices are in better shape and are worth more. The faster we can add new device assessments, the more money the company makes.
Alex: Wow, so rapid change is a BIG deal for this service.
Mara: It is! And don’t forget, we have to make sure that supporting new devices won’t affect the system’s support for the existing ones. Are y’all up for it?
Sam and Alex: You bet!
Mara: I think we should consider using a microkernel architecture. That style makes it easier to design and add new capabilities using plugins.
The two parts of microkernel architectures
The microkernel architecture derives its name from operating system design. The kernel , or core, of an operating system is very small, offering only the most basic capabilities. A microkernel architecture consists of two primary parts: its core and its plugins (any number of them).
there are no Dumb Questions
Q: Is the microkernel architecture technically or domain-partitioned?
A: Flashback to Chapter 5 ! Most microkernel architectures are technically partitioned. You could divide the core into layers—perhaps one for presentation, another for business or workflow logic, and so on. However, microkernel is one of those strange architectural styles that can also be domain-partitioned, depending on how you design your plugins.
As for deployment models, microkernel architectures are usually monolithic. As you’ll see in this chapter, however, in some scenarios a distributed model might make more sense.
Not quite. Every microkernel has plugins, but not all plugins belong to microkernels. Unfortunately, there is no definitive dividing line between microkernel systems and systems that support plugins. Mostly, we evaluate how “microkernel-y” an architecture is (let’s call that “microkern-ality”) by how functional its core is without any plugins and how volatile its core is (how often it needs to change).
The spectrum of “microkern-ality”
Lots of software supports plugins: IDEs, web browsers, build tools, you name it. But simply supporting plugins doesn’t make a system a microkernel—it’s all about the core. In extreme microkernels, the core can do very little useful work without plugins installed.
there are no Dumb Questions
Q: Is every system that supports plugins a microkernel?
A: Not at all. Lots of systems support plugins. How much of a microkernel it is (and no one is actually grading you on this) depends on the volatility and functionality of its core.
Q: Is this architectural style only useful for software development tools?
A: A lot of development tools use this architecture because it lets them offer programmatic customization, but many business and other applications use it too. It works for any problem domain that requires customization and in which each change acts in isolation.
Q: Are microkernel and microservices the same thing?
A: No, the similarity in the names is just a coincidence. Microkernel’s name comes from operating system design, whereas microservices is named for its relatively small and separate deployment units in a distributed architecture.
Exercise
The microkernel architectural style shows up in lots of places. See if you can place the specific tools and categories below in the correct place on the spectrum, by determining how much of a microkernel each one is. Hint: Each system’s degree of “microkern-ality” depends on how useful it is without plugins.
Solution in “Exercise Solution”
Device assessment service core
You and your team all agree to use a microkernel architecture for the new device assessment service.
The core system includes the criteria needed to assess a device, like its age, condition, and model number. For each type of device, it defers to a device-specific plugin that executes the rules to determine how the system will assess the device’s resale value.
You decide to use a distributed physical architecture for the plugins, for better scalability. This also gives Going Green the option to add plugins in other languages in the future.
Finally, you decide on synchronous communication, because the service is sufficiently responsive that there’s no need to add the complexity of asynchronous communication.
Let’s dig into those decisions a little further.
Yes, we could! The architecture’s capabilities determine whether to encapsulate or distribute the plugins.
Some microkernel architectures include both the core system and the plugins in a single monolithic architecture; others are distributed, as you might recall from Chapter 5 .
The microkernel style exists in the shadowy netherworld between monolithic and distributed architectures. Architects can implement it with either deployment model.
there are no Dumb Questions
Q: Does a microkernel architecture’s core system have to be a monolith?
A: Not necessarily—microkernels often feature in hybrid architectures. When it makes sense (such as for a desktop application), you might implement the core as a single system; other times, you might distribute parts of the core as well as the plugins.
Q: How do I implement plugins?
A: You can implement your own plugin designs using interfaces, but virtually all platforms and technology stacks have libraries and frameworks to help out.
Q: Can I implement plugins in different tech stacks than the stack in which the core is written?
A: One of the advantages of using distributed plugins is that you can write them using any platform you can call via a network connection.
Encapsulated versus distributed plugins
The core system in a microkernel is where the plugins, well, plug in. Generally, we implement that connection via an interface . The plugin implements the interface, while the core system supports that component via that interface.
If we design a microkernel as a monolithic architecture, we’ll implement each plugin as a component that connects to the core through the interface.
In other implementations of microkernel architectures, plugins are distributed: web endpoints, event queues, and so on. In addition, we can decide whether to call the plugins synchronously or asynchronously. (We’ll cover this in much more depth in Chapter 11 .)
Exercise
The assessment service team at Going Green must decide whether the microkernel’s physical architecture should be monolithic (core and plugins in the same deployment unit) or distributed (plugins deployed separately from the core). They need your help with the trade-off analysis. Can you list some pros and cons for each option? We’ll get you started. Hint: Consider how each option would affect things like architectural characteristics.
Solution in “Exercise Solution”
Plugin communication
To be useful, plugins must communicate with the core system. For example, the core will call a method (based on an interface) and utilize the results. This communication can be implemented in a couple of different ways, based on factors like physical architecture.
How the actual call happens between the core and a plugin depends on the physical architecture you use to implement the plugins. In monolithic architectures, we implement plugins in the same technology stack as the core and deploy them as native components for the platform (like JAR files for Java, DLLs for .NET, or GEMs for Ruby).
As for distributed plugins, the core can call them with synchronous or asynchronous calls. Developers aren’t restricted to the core’s implementation platform, either—they can write plugins in a variety of languages.
Today’s Interview
Plugging into the star attraction of the microkernel: the Plugin
Head First: Let’s see... let me get my microphone plugged in. Testing, testing... OK, welcome, Plugin!
Plugin: How appropriate! All sorts of things use me to function. I’m happy to be here—and excited to clear up some controversies.
Head First: Everyone says you’re the star of the microkernel architecture, yet the core gets more press time and attention. Is that fair?
Plugin: Well, that may be true, but what good is the core without me? It may be bigger, but without me, the core is boring .
Head First: You certainly show up in lots of places. What about your controversial role in non-microkernel architectures? Lots of systems support plugins that aren’t microkernels...
Plugin: I’m happy wherever I appear. To be truthful, though, I prefer microkernels. For other architectures, plugins are just condiments—we’re not necessary, but we add some nice flavors. In a microkernel, though, I’m the main course! The whole architecture is based on me. I appreciate that level of importance.
Head First: Let’s dig into something that seems to appear in trade-off analyses all the time. Your distributed version has some performance issues, no?
Plugin: Hey, you can’t say bad things about all plugins just because we have some trade-offs! Yes, it’s true that when we use network calls to communicate, performance does take a hit. But you know what else? Those distributed plugins can scale better, and you can write them in a variety of languages. Different strokes for different folks, right? And different plugin physical architectures for different trade-offs.
Head First: OK, fair enough. But let’s talk about working with overly volatile cores.
Plugin: Alas, that’s one of the downsides to starring in a microkernel architecture—when the core decides to change all the time. Change is my job! The more the core changes, the more it’s likely to interfere with what I’m doing. I strive for professionalism, so I prefer to work with nice, stable cores with no drama.
Head First: You get a lot of press because of your ability to handle customization, but do you have other roles? What else you can handle?
Plugin: Thanks for asking, Head First. It’s always annoying to be pigeonholed into my best-known role. I can handle customizations without ugly, long switch statements, using an elegant architectural style, without even batting an eye. We plugins can be used for all kinds of things—really, anything that needs good isolation. For example, I show up all the time in A/B testing. The architects keep the old behavior in PluginA, add the new behavior in PluginB, and decide which to call. I also have starring roles in integration hubs, developer tools, and lots of other places.
Head First: Before we finish up, is there anything you’d like to plug?
Plugin: You bet! Look for me in an architecture near you, either as an integral part of a monolith or as an endpoint for a distributed microkernel.
Cubicle conversation
Mara: Hi, all. Just stopping by to take a look at your trade-off analysis for the Going Green assessment service. Have you decided yet between a monolithic and a distributed physical architecture?
Sam: We’re working on it. I did the trade-off analysis for the distributed version, and personally, I’m a big fan. Here’s our summary:
Mara: Can you explain how you arrived at these conclusions?
Alex: Sure. For the distributed version, we don’t have to restart the core system to add new devices. That gives us better availability than the monolithic version, since that requires a restart to load new device plugins. Also, it’s simpler to deploy a single plugin than to redeploy the whole assessment service. Since the plugins don’t run in the same process as the core, we can make the whole system more scalable . But that would take a toll on its performance —after all, network calls take a lot longer than in-process ones.
Mara: That sounds like a good trade-off. The business agrees that scalability is very important for the new system.
there are no Dumb Questions
Q: Where is the user interface in a microkernel architecture?
A: It depends! If the system is monolithic, architects commonly include the UI as part of the core system. However, when you design a service in a distributed architecture as a microkernel, other parts of the system typically handle the UI.
Q: Can the UI utilize a microkernel?
A: You bet it can. In fact, lots of UI patterns (like the BFF pattern we mentioned earlier) use the microkernel structure to handle customized UI endpoints such as iOS, Android, and web browsers.
Q: Isn’t a microkernel really just the Decorator design pattern?
A: Good catch! While their purposes are mostly the same, the microkernel architecture is one way to implement the Decorator design pattern. Compared to design patterns, architecture requires more thought about physical limitations and possibilities. For example, design patterns don’t account for capabilities like scalability.
Q: Is the microkernel style the only way to handle customization?
A: Not at all. It’s one of many ways. A microkernel architecture is useful when the structure of your system—its core capabilities that rarely change—requires discrete customization via plugins. For systems without that kind of structure, other architectural styles may be more appropriate.
Q: What’s the internal structure of the core system? Is it just one big logical component?
A: In the microkernel style, we design the core system based on how we want to organize the logical components in the system. For example, if we want to separate capabilities within the core, we might choose to implement the core via layers, as we would in the layered architectural style. On the other hand, we might follow DDD and design the core around a bounded context, as in the modular monolith style. The microkernel style is often used in hybrid architectures where customizability is a driving characteristic.
Plugins can talk to one another in a microkernel through the core system. But should they?
Plugins typically communicate with the core system by implementing an interface that the core supports. That makes it possible for plugins to communicate with each other “through” the core system. For example, the Eclipse IDE, which supports multiple languages, allows language-based tools (like compilers and debuggers) to interact with each other in this way.
Be cautious about allowing inter-plugin communication, though! It has some serious negative trade-offs. First, it requires consistent contracts between the core and the plugins, which eventually involves versioning. (More about contracts on the next page.) For example, one thing that makes Eclipse complex is the transitive dependencies between its components, which can cause versioning headaches. Second, dependencies between plugins create availability issues, because you must guarantee that all necessary plugins are present at runtime.
To understand the problems with letting plugins chat amongst themselves, we have to look at the two ways the core communicates with plugins.
Plugin contracts
When architects implement microkernel architectures, we usually ensure that the core calls plugins using a contract (another word for interface ). That communication is solely between the plugin and the core , not between plugins. If you allow communication between plugins, the core has to act as their intermediary.
In the example system below, PluginA doesn’t know or care about other plugins; it communicates only with the core. However, PluginX needs to communicate with PluginY, and that communication must be mediated by the core system.
Brain Power
You know you have to worry about intermediary communication through the core system, but consider this: what happens when you update PluginY in a way that changes the contract between PluginX and PluginY? If you don’t want to change PluginX when you change PluginY, how could you manage that communication?
Going Green goes green
After considering how best to implement the plugin interaction with the core, the team decides to define an interface (called DeviceInterface ) for each plugin to implement. Now Going Green can add new devices just by implementing the interface and customizing the valuation process for that specific device.
Your device assessment engine is a success. Well done!
To wrap up, let’s quickly summarize the strong and weak points of this style of architecture.
Microkernel superpowers
The microkernel is a common architectural style. It’s also one of the most common styles you’ll find within hybrid architectures that require customization.
Custom behavior
The microkernel is “shaped” in the best way to handle customizations.
Note
Who you gonna call to customize part of your application? Microkernel to the rescue!
Evolvability
Evolvability , as an architectural characteristic, means that architects can make fundamental underlying changes that gradually evolve the system away from its old behaviors. Unlike adaptable architectures, evolvable architectures only support the old behaviors for a short time. Plugins offer an excellent way to implement this capability.
Partitioning
In a microkernel, you can handle customization with design or with architecture. However, if you use design, the developers must be very diligent about following the design correctly. If the system is structured around plugins, the distinction is clearer.
Note
The microkernel is a great example of an architectural approach to customization
Adaptability
Adaptability , as an architectural characteristic, implies the ability to keep existing functionalities and continue adding more. A microkernel supports this well; you can keep old plugins as you implement new ones.
Simple structure
A microkernel has two basic moving parts (the core and plugins), making it easy for developers to understand and implement.
Note
Simplicity for the win!
Microkernel kryptonite
The microkernel architecture’s weaknesses mostly appear when architects use it improperly: for example, when the core changes too much or when plugins must communicate heavily with one another.
Misaligned volatility
In a microkernel, the core system should change very little once it is implemented. If it changes a lot, that is likely a sign that this is not the ideal architectural solution or you have made the wrong things plugins.
Note
One of the most common mistakes in a microkernel is a too-volatile core, due to frequent domain changes.
Sharing between plugins
While it’s often tempting, sharing dependencies (such as shared libraries) between plugins is generally a bad idea because it creates headaches around coupling and deployment.
Note
To keep a microkernel from devolving into a big ball of mud, keep an close eye on coupling via sharing.
Chatty plugins
Allowing plugins to interact may be tempting, but it comes with a host of difficult trade-offs. Successful systems that use this approach (for example, Eclipse) do so at the cost of high complexity.
Performance
When using distributed plugins for a physical architecture, you might notice an impact on performance, depending on the communication protocols and how much information passes between the core and the plugins.
Microkernel star ratings
We’ve created a chart of star ratings, like the ones we showed you for layered and modular monolith architectures, to indicate how well microkernel architectures do with each of the architectural characteristics listed. One star means that the architectural characteristic is not well supported; five stars means it’s very well supported.
Note
Just like movie reviews.
Exercise
Which of the following systems might be well suited for the microkernel architectural style, and why? Hint: Take into account its superpowers, its kryptonite, and the nature of each system.
Solution in “Exercise Solution”
Wrapping it up
Thanks to your efforts, Going Green is assessing devices quickly and accurately, and profitability has never been better. This case shows just how useful microkernel architectures can be. For problems that need a customizable, stable system, a microkernel is hard to beat.
Bullet Points
-
The microkernel architectural style provides a structured way to handle customizations via plugins.
-
Microkernel architectures consist of two main parts: the core and one or more plugins .
-
The core system in a microkernel contains minimal functionality and has low volatility.
-
Architects design plugins to customize and/or add behaviors to a system.
-
Generally, plugins only communicate with the core system, not with each other.
-
If plugins do need to communicate with each other, the core must mediate the communication and handle issues like versions and dependencies. It essentially serves as an integration layer.
-
Microkernel architectures can be monolithic architectures or can be implemented as services in a distributed architecture.
-
When built as a monolithic architecture, the core and plugins must be written in the same language.
-
Plugin calls may be synchronous (for example, using REST in a distributed architecture) or asynchronous (using threads in a monolithic architecture or messaging in a distributed one). Whether remote calls are synchronous or asynchronous, architects can implement the plugins in a variety of technology stacks.
-
Monolithic plugins generally offer better performance because calls take place in the same process.
-
Monolithic microkernels suffer from the typical limitations of all monoliths, including limited operational capabilities such as scalability and elasticity.
-
Microkernels that use distributed plugins may offer better scalability, because they use multiple processes and offer scalable communications (events).
-
Microkernel architectures are best suited for problems with distinct categories of volatility.
-
If a microkernel’s core system changes often, its architects may have chosen the wrong architectural style or may have partitioned the work incorrectly.
-
The microkernel style shows up in lots of places: IDEs, text processing tools, build and deployment tools, integrations, translation layers, insurance applications, and electronics recycling applications, just to name a few.
Microkernel Crossword
Ready to see how much you’ve learned about microkernel architecture? Plug into this crossword puzzle!
Across
3. Design pattern often used to implement microkernel architectures
6. With inter-plugin communication, the core serves as an integration _____
9. You can add new capabilities to a system by using these
10. Microkernel architectures can _____ to include new functionalities
11. Abbr. for a tool used to write code
13. Monolithic architectures _____ both plugins and core
14. Plugins are usually _____ independently from each other
16. A microkernel is great for creating systems with _____ rules and behaviors
17. You can use plugins written in more than one tech _____
Down
1. When plugins can talk to each other, their dependencies are _____
2. Example of an IDE that uses interacting plugins
4. _____ plugins provide better performance
5. Number of primary component types in a microkernel architecture
7. Constantly changing
8. Microkernel architectures often support several programming _____
12. When most monoliths load plugins
15. A tool that applies style and syntax rules to code
16. Plugins make _____ to talk to the core
18. What plugins are plugged into
Solution in “Microkernel Crossword Solution”
From “BE the architect”
BE the architect Solution
Architects just can’t stop analyzing stuff. Can you determine a few important architectural characteristics for each of the three services in the new Going Green architecture?
From “Exercise”
Exercise Solution
The microkernel architectural style shows up in lots of places. See if you can place the specific tools and categories below in the correct place on the spectrum, by determining how much of a microkernel each one is. Hint: Each system’s degree of “microkern-ality” depends on how useful it is without plugins.
From “Exercise”
Exercise Solution
The assessment service team at Going Green must decide whether the microkernel’s physical architecture should be monolithic (core and plugins in the same deployment unit) or distributed (plugins deployed separately from the core). They need your help with the trade-off analysis. Can you list some pros and cons for each option? Hint: Consider how each option would affect things like architectural characteristics.
From “Exercise”
Exercise Solution
Which of the following systems might be well suited for the microkernel architectural style, and why? Hint: Take into account its superpowers, its kryptonite, and the nature of each system.
Microkernel Crossword Solution
From “Microkernel Crossword”