There are lots of different architectural styles out there. Each one exists for a reason and has its own philosophy about how and when it should be used. Understanding a style’s philosophy will help you judge whether it’s the right one for your domain. This chapter gives you a framework for the different kinds of architectural styles (which we’ll be diving into for the remainder of this book), to help you make sense of these and all the other architectural styles you’ll encounter as a software architect.
Let’s fill in that final piece of the puzzle, shall we?
There are lots of architectural styles
You’ve learned a lot about software architecture so far, but there’s one thing we still haven’t talked about: architectural styles . That’s what we’ll do in this chapter—in fact, the rest of this book is dedicated to architectural styles!
Before we get started: look around your neighborhood, then watch a show or movie set in a different part of the world. How many styles of homes do you see? There are literally hundreds—all influenced by the locale, weather, and the owners’ personal preferences. New styles are created every day.
That’s true for architectural styles in software, too. There are so many out there that even in a book this big, try as we might, we’ll barely scratch the surface of all the available styles.
This chapter will give you a framework for thinking about architecture and architectural styles in general. Then, in the chapters that follow, we’ll dive deep into a handful of specific architectural styles and examine their philosophies, using what you learn in this chapter. Understanding a few crucial styles will leave you with a good foundation to understand others as you encounter them.
Let’s do this.
The world of architectural styles
If you’ve done software development for any length of time, you may have heard about different architectural styles, like monoliths and microservices. To help us think systematically about them, we place them into two categories. The first deals with how the code is divided: either by technical concerns or by domain (business) concerns. The second category is about how the system is deployed: is all the code in the system delivered as one unit, or as multiple units?
Note
Recall from Chapter 2 that the domain is “the thing you’re writing software about.”
As you can see, there are multiple ways to slice and dice architectural styles. This doesn’t cover everything, of course—there are domain-specific architectures that are built explictly for certain problems—but a book can only be so long.
Note
We won’t spend time on domain-specific architectures in this book. Let’s just say they don’t appeal to a broad audience.
Each category reveals some of the architectural characteristics of its styles. For example, architectural styles delivered as one unit are easier to understand, but those delivered as multiple units tend to scale better.
Let’s examine each category.
Partitioning: Technical versus domain
Think back to the last time you had dinner at a fancy restaurant. When you walked in, a host probably greeted you and escorted you to a table. A server offered you drinks and menus and explained the specials. The chef and other cooks prepared your food for you. When you finished your meal, a busser cleaned and reset the table.
These restaurant workers’ duties are separated by technical concern . A busser’s role isn’t to welcome you, and you probably don’t want the server cooking your food.
Now, think back to the last application you worked on. Did it have a controller layer? Did it have services? How about a persistence tier? If so, congratulations: you’ve already worked on a technically partitioned architecture.
In a technically partitioned architecture , code is divvied up by technical concerns—there might be a presentation tier, a business (services) layer, and so on. The principle at play here is separation by concern—which most people think about in horizontal layers.
Note
Another analogy that might help is a burger, with two halves of a bun, condiments, veggies, and a patty—each layer has a distinct and separate role.
On the other hand, imagine a food court. It has lots of restaurants, each specializing in a particular kind of food: pizza, salads, stir-fry, burgers. In other words, each restaurant has a specific domain .
Note
Each of these restaurants might have servers and bussers. But at a high level, the restaurant specializes in a particular kind of food.
Note
We’ll dive into a lot of these details in future chapters.
In domain-partitioned architectures , the structure of the system is aligned with the domain. Rather than by roles, the code (and systems) are separated in ways that align with the problem you’re attempting to solve.
there are no Dumb Questions
Q: In a domain-partitioned architecture, where do the presentation and services layers reside?
A: In a domain-partitioned architecture, you are making the domain the “first-class citizen,” leaving the technical implementation as just that: implementation. The logical components that make up your architecture are organized around the domain , as opposed to the role they perform.
A technically partitioned architecture’s components might be organized in namespaces like app.presentation.customer or app.services.customer . Note how the customer domain appears within the technical partition. However, in a domain-partitioned architecture, you’ll have namespaces like app.customer.presentation and app.customer.services .
Q: Domain partitioning is pretty logical. Frankly, it sounds better. So why would anyone use technical partitioning?
A: We prefer not to use value judgments such as “better” and “best” when discussing architectural styles. (You’re going to get tired of us saying this!) Your choice of architectural style will always be driven by a variety of factors, as you know, including the domain and the required architectural characteristics.
Technical partitioning is great if your teams tend to specialize—say, if you have teams of frontend experts, backend developers, and database administrators. But domain partitioning better aligns your system with the actual problem at hand.
Exercise
A short-order cook pretty much does everything. They can cook everything on the menu, from fries to sandwiches, as well as blending smoothies and plating desserts. Often, they also serve food, take payments, and even clean tables after customers leave. Would you categorize a short-order cook’s work as partitioned technically or by domain? Why? Jot down your thoughts here.
Solution in “Exercise Solution”
Deployment model: Monolithic versus distributed
Let’s play a game—we say a word, and you respond with the first thing that pops into your mind. Ready? Monolith .
We don’t know about you, but this word makes us think of something like a boulder or a glacier—something big . That’s exactly what monolithic architectures represent.
In a monolithic architecture , you deploy all the logical components that make up your application as one unit . This also means that your entire applications runs as one process.
Note
This would be like packaging and deploying your entire application as a single WAR or JAR file in the Java ecosystem, or as an executable in the .NET world.
In a distributed architecture , by contrast, you split up the logical components that make up the application across many (usually smaller) units. These units each run in their own process and communicate with each other over the network.
There’s a lot to this distinction, so let’s talk about the pros and cons of both types.
Exercise
Take a moment and consider your smartphone. It does it all—it lets you take pictures and videos, browse the web, post to your favorite social networking site, track your fitness activity, and navigate via GPS. And somewhere, embedded deep within the settings, there’s even a phone! As you can see, your phone is a monolithic system. We’d like you to jot down the pros and cons of such a system. Think in terms of architectural characteristics, like availability, upgradability, cost, and ease of use.
Just a few years ago, people used separate devices for all those functions your phone performs today. Phones were, well, just phones , maybe with text messaging. We used laptop or desktop computers to browse the web and post to social networking sites; we could buy fitness trackers to help track workouts and GPS devices to install in cars for navigation help. Each of these “services” was deployed separately.
Just like you did above, jot down the pros and cons of such a system. Again, think in terms of architectural characteristics.
Solution in “Exercise Solution”
Monolithic deployment models: The pros
In Chapter 2 , you learned that architectural characteristics always influence some structural aspect of the design. Monoliths support some characteristics better than distributed systems, and knowing where they shine can help you decide when to use them.
Because monolithic systems run in one process, they make development easier—at least initially. And since they’re deployed as one unit, tracing errors is a lot easier.
Let’s take a look at the pros and cons of both deployment models, starting with monoliths. Here are the pros:
Now for the cons...
Monolithic: The cons
Some of monoliths’ strengths can become problematic as an application grows. Many of the operational characteristics we discussed in Chapter 2 , like scalability and reliability, suffer as a monolithic application grows bigger and more complex.
Next, we’ll look at the pros and cons of distributed architectures.
Brain Power
Spend a few minutes thinking about your industry. Does your organization have any special regulatory, security, or compliance needs? How might using a monolithic architecture help or hurt its ability to achieve the architectural characteristics that address those needs? List any ways you can think of here:
Distributed deployment models: The pros
With distributed architectures, you deploy your logical components as separate units. This makes it easy to scale some parts of your application separately from others. And since logical components are physically separate, distributed architectures encourage low coupling .
So, what architectural characteristics are distributed architectures good for? Here’s a sampling:
As you might have noticed, distributed architectures do better on many of monolithic architectures’ weak points. But is the opposite true? Let’s find out.
Distributed deployment models: The cons
Can’t have pros without cons. Trade-offs, right? It’s all about trade-offs.
Distributed architectures make some things easy, while making others very hard.
Watch it!
It’s easy to underestimate how hard distributed computing is!
For all their benefits, distributed architectures depend on the network. Software architects often underestimate the complexities that arise from this dependency. Look up “The Fallacies of Distributed Computing,” a list compiled in the 1990s by L. Peter Deutsch and others at Sun Microsystems, to get a sense of what to watch out for.
Brain Power
Let’s repeat the exercise you did earlier, this time for distributed architecture. Does your organization have any special regulatory, security, or compliance needs? How might using a distributed architecture help or hurt your organization’s ability to achieve the architectural characteristics that address those needs? List any ways you can think of here:
Fireside Chats
Tonight’s talk: Monolithic and distributed architectures answer the question: “Who’s more relevant?”
| Monolithic Architecture | Distributed Architecture |
|---|---|
| It’s a good thing I’m still around. Boy, do you make things complicated. | |
| I don’t like that attitude. Sure, you might be “simpler” to develop, but you can’t keep up. Businesses need to move fast, and you just don’t deliver the goods. | |
| I might be simple, but I’m also faster to develop. I can’t imagine anyone building a minimum viable product with you—they’d never launch! | |
| I might give you that—but I’ll make sure they make it to the finish line. And if their product is a smash hit, will you help or just get in the way? I can ensure success even at scale. | |
| Oh! And I’m way cheaper. You realize that most businesses don’t want to waste money, right? I can’t imagine anyone using you to create a proof of concept. | |
| Businesses also like making money. Once their applications grow, you’re just a money pit. I personify agility—I help teams and organizations scale as they grow.I also make testing easier, while you just rack up the technical debt. | |
| It’s a good thing you can be tested easily—ever seen a useful error stack trace? Of course you haven’t. You’re all over the place. Good luck trying to trace why and where an error actually happened.At least when I get an error, you get a nice, clear stack trace. | |
| Riiiight. And when you fail, you just topple over. I provide a high degree of fault tolerance. Need a service to scale? Just scale that service. Scaling you is arduous. | |
| At least I’m just one process. No unnecessary network traffic here. You’re all talk, man—so much chatter. All your services are constantly talking to one another.And that’s only if the network is always reliable, because without it, you have nothing! Heaven help you if the network should fail.Plus, with me, you don’t need a whole bunch of network infrastructure. Do you know how expensive that stuff is to maintain?! | |
| Hey, that’s the cost of doing business at scale. Teams might start with you, but if they want to keep growing, they’ll come to me—and leave you in the rearview mirror. | |
| What? Are you saying I’m old news? Well, the next time a team needs to get to market quickly, don’t call me—and then we’ll see how tough you really are. | |
| Feeling’s mutual, bud. Don’t call me when your team’s minimum viable product is a success and their architecture can’t handle all the attention. |
And that’s a wrap!
Now you know how to categorize the tons of architectural styles out there. Having a framework can help you make sense of them. And remember—each quadrant of the framework represents both the pros and cons of those architectural styles.
In the next chapter, we’ll start our deep dive into individual styles.
Bullet Points
-
There are a lot of architectural styles—in fact, too many to count.
-
There are multiple ways to categorize architectural styles. One is by their partitioning style . Architectural styles can be either technically partitioned or domain partitioned.
-
In technically partitioned architectural styles, the code is split up by technical concern. For example, there might be a presentation layer and a services layer.
-
In domain-partitioned architectural styles, the code is instead split up by problem domain.
-
Another way to categorize architectural styles is by their deployment model . Monolithic architectural styles deploy all the logical components that make up an application as a single unit. Distributed architectural styles deploy the logical components separately from one another, as multiple units.
-
Monolithic architectures are easier to understand and debug and are often cheaper to build (at least initially). This makes them great candidates if there is a rush to bring a product to market.
-
As monolithic applications grow, scaling them up can become arduous. It’s an all-or-nothing scenario: you either scale up the whole application or nothing at all.
-
Monolithic applications can also be unreliable—a bug can make the entire application unusable.
-
Distributed architectures are highly scalable since their logical components are deployed separately, allowing different parts of the application to scale independently of one another.
-
Distributed architectures encourage a high degree of modularity, which means testing them is easier.
-
Distributed architectures are extremely expensive to develop, maintain, and debug.
-
Distributed architectures use the network so that different services can talk to one another to complete work. This introduces even more complexity.
Stylin’ Architectures Crossword
Now that you can make sense of architectural styles, see if you can make sense of this crossword.
Across
2. You can _____ systems technically or by domain
3. L. Peter _____ helped compile “The Fallacies of Distributed Computing”
7. Monoliths are good for creating a _____
10. Regardless of the physical architecture, a _____ system provides more confidence in correct outcomes
14. Distributed and monolithic are both deployment _____
15. Minimum viable _____
17. Monolithic systems are easier to _____
18. Monolithic architectures have _____ deployment units
Down
1. Layers are separated by _____
2. Each architectural style has its own _____
4. Monolithic architectures tend to have a fast _____ to market
5. A system deployed as one big unit
6. If you change anything in a monolith, you’ll need to _____
8. An architecture’s organization is reflected in its _____ spaces
9. Services in a distributed architecture use this to communicate
11. Distributed systems consist of many _____ deployment units
12. Nothing about distributed deployment models is _____
13. Architectures often have more than one _____
16. Distributed systems usually _____ more than monolithic ones do
Solution in “Stylin’ Architectures Crossword Solution”
From “Exercise”
Exercise Solution
A short-order cook pretty much does everything. They can cook everything on the menu, from fries to sandwiches, as well as blending smoothies and plating desserts. Often, they also serve food, take payments, and even clean tables after customers leave. Would you categorize a short-order cook’s work as partitioned technically or by domain? Why? Jot down your thoughts here.
Note
Because a short-order cook does everything needed to get customers their meals, from setting the tables to prepping and cooking to cleaning up, they own the whole “domain” of food preparation. This makes their job domain-partitioned.
From “Exercise”
Exercise Solution
Take a moment and consider your smartphone. It does it all—it lets you take pictures and videos, browse the web, post to your favorite social networking site, track your fitness activity, and navigate via GPS. And somewhere, embedded deep within the settings, there’s even a phone! As you can see, your phone is a monolithic system. We’d like you to jot down the pros and cons of such a system. Think in terms of architectural characteristics, like availability, upgradability, cost, and ease of use.
Just a few years ago, people used separate devices for all those functions your phone performs today. Phones were, well, just phones , maybe with text messaging. We used laptop or desktop computers to browse the web and post to social networking sites; we could buy fitness trackers to help track workouts and GPS devices to install in cars for navigation help. Each of these “services” was deployed separately.
Just like you did above, jot down the pros and cons of such a system. Again, think in terms of architectural characteristics.
Stylin’ Architectures Crossword Solution
From “Stylin’ Architectures Crossword”