Image

What happens when there are no “best practices”? The nice thing about best practices is that they’re relatively risk-free ways to achieve certain goals. They’re called “best” (not “better” or “good”) for a reason—you know they work, so why not just use them? But one thing you’ll quickly learn about software architecture is that it has no best practices. You’ll have to analyze every situation carefully to make a decision, and you’ll need to communicate not just the “what” of the decision, but the “why.”

So, how do you navigate this new frontier? Fortunately, you have the laws of software architecture to guide you. This chapter shows you how to analyze trade-offs as you make decisions. We’ll also show you how to create architectural decision records to capture the “hows” and “whys” of decisions. By the end of this chapter, you’ll have the tools to navigate the uncertain territory that is software architecture.

It starts with a sneaker app

Archana works for Two Many Sneakers, a company with a very successful mobile app where shoe collectors (“sneakerheads”) can buy, sell, and trade collectible sneakers. With millions of shoes listed, customers can find the shoes they really want or upload photos to help sell the ones they don’t.

Image

The app’s initial architecture was a single service as shown below:

Image

The Two Many Sneakers app knows to talk to the trading service to fetch and update data (like a photo of a mint-condition pair of Nikes). The trading service, in turn, fetches data and updates the database.

Business is booming. Sneakerheads are always willing to change up their collections, and Two Many Sneakers’ customer base has grown quickly. Now customers are demanding real-time notifications, so they’ll know whenever someone lists a pristine pair of those Air Jordans they’ve been pining for.

Security is always a concern in online sales. Nobody wants knockoffs, and credit card numbers need to be protected. To stay a few steps ahead of any scammers, Two Many Sneakers’ management team wants to prioritize improving the app’s fraud detection capabilities. They plan to use data analytics to help detect fraud by spotting anomalies in user behavior and filtering out bots.

Image

Work has already begun—all the team needs to do now is set up the trading service to notify the new notification and analytics services anytime something of interest happens in the app.

Image

What do we know so far?

We need to figure out how these services will communicate with one another. Let’s recap what we know (and don’t know) so far:

  • The current architecture is rather simple—the trading service talks to its own database, and that’s that. We need the trading service to send information to the notification service and the analytics service.

    Image

  • Word in the office is that there’s a chance that the finance department (which is responsible for compliance) will want updates from the trading service. In other words, whatever architecture we come up with will need to be extensible .

    Image

  • We don’t know what data to send the notification and analytics services—do the two services get the same kind of data, or wildly different data? And we don’t know where things stand with finance, so that’s another unknown.

    Image

To be clear, there are some things we know and plenty we don’t. Welcome to the world of software architecture.

Note

As the system’s architects, we need to identify its architectural characteristics. (You learned about those in Chapter 2 .)

Speaking of architecture, we’ll be done, say, next Thursday—right?

Exercise

Image

Which of the following architectural characteristics stand out as important for this particular problem? Hint: There are no right answers here, because there is a lot we don’t know or aren’t sure of yet. Take your best guess—we’ve provided our solution at the end of this chapter. We’ll get you started:

Image

Images Solution in “Exercise Solution”

Brain Power

Image

All the characteristics in the previous exercise sound pretty good, right? Seriously, who’d say no to upgradability?

But for each one, ask yourself— is this characteristic critical to the project’s success? Or is it a nice-to-have?

What’s more, some characteristics conflict . A highly secure application with loads of encryption and secure connections probably won’t be highly performant. Go back and see if any of your choices are at odds. If so, you can only pick one.

Note

Flashback to Chapter 2 ? You bet it is!

there are no Dumb Questions

Q: Even this simple exercise seems to have a lot of moving parts. We know some things, we think we know some other things, and there’s a lot that we certainly don’t know. How do we go about thinking about architecture?

A: You’re right. In almost all real-life scenarios, your list of architectural characteristics will probably contain a healthy mix of “this is what we want” and “this is something we might want.” Even your customers can’t answer the question of what they will eventually want. (Wouldn’t that be nice?) This is the “stuff you don’t know you don’t know,” also known as the “unknown unknowns.”

It’s not unusual for an “unknown unknown” to rear its head midway through a project and derail even the best-laid plans. The solution? Embrace agility and its iterative nature. Realize that nothing, particularly software architecture, remains static. What worked today might prove to be the biggest hurdle to success tomorrow. That’s the nature of software architecture: it constantly evolves and changes as you discover more about the problem and as your customers demand more of you.

Communicating with downstream services

Our goal is to get the trading system to notify the reporting and analytics systems automatically. For now, let’s assume we decide to use messaging. But that presents a dilemma—should our messaging use queues or topics?

Note

It’s OK if you don’t know much about messaging, queues, or topics. We’ll tell you what you need to know.

Before we go further, let’s make sure we’re on the same page about the differences between queues and topics. Most messaging platforms offer two models for a publisher of a message (in this case, that’s the trading service) to communicate with one or more consumers (the downstream services).

The first option is a queue , or a point-to-point communication protocol. Here, the publisher knows who is receiving the message. To reach multiple consumers, the publisher needs to send a message to one queue for each consumer. If the trading service wants to use queues to tell the analytics service and the reporting service about trades, this is what the setup will look like:

Note

If it helps, think of queues as being like a group text—you pick everyone you want to inform, type your message, and hit “send.”

Image

When using the second option, topics , you are signing on for a broadcasting model. The publisher simply produces and sends a message. If another service downstream wants to hear from the publisher, it can subscribe to the topic to receive messages. The publisher doesn’t know (or care) how many services are listening.

Note

Topics are similar to posting a picture on your go-to social networking site. Anyone following you will see that picture, since they’ve “subscribed” to your timeline.

Image

Both options sound good—so how do we pick? Let’s find out.

Analyzing trade-offs

You can’t have your cake and eat it too. The world is full of compromises—we often optimize for one thing at the cost of another. Want to take and store lots of pictures on your phone? Either get more storage, which costs more, or compress them, which lowers the image quality.

Image

Software architecture is no different. Every choice you make involves significant compromises or, as we like to call them, trade-offs . So what exactly does this mean for you?

Note

If this sounds familiar, it should be! It was part of our discussion of significant versus less-significant trade-offs in Chapter 1 .

If you know which architectural characteristics are most important to your project, you can start thinking of solutions that will maximize some of those attributes. But if a solution lets you maximize one characteristic (or more), it will come at the cost of other characteristics. For example, a solution that allows for great scalability might also make deployability or reliability harder.

No matter what solution you come up with, it will come with trade-offs—upsides and downsides.

Your job is twofold: know the trade-offs associated with every solution you come up with, and then pick the solution that best serves the most important architectural characteristics.

Note

Rich Hickey, creator of the Clojure programming language, once said, “Programmers know the benefits of everything and the trade-offs of nothing.” We’d like to add: “Architects need to understand both .”

You can’t have it all. You’ll have to decide which architectural characteristics are most important, and choose the solution that best allows for those characteristics.

Trade-off analysis: Queue edition

Trade-off analysis isn’t just about finding the benefits of a particular approach. It’s also about seeking out the negatives to get the full picture. Let’s look at each option in turn, starting with queues.

With queues, for every service that the trading service needs to notify, we need a separate queue. If the notification service and the analytics service need different information, we can send different messages to each queue. The trading service is keenly aware of every system to which it communicates, which makes it harder for another (potentially rogue) service to “listen in.” (That’s useful if security is high on our priority list, right?) Oh, and since each queue is independent, we can monitor them separately and even scale them independently if needed.

Image

The trading service is tightly coupled to its consumers—it knows exactly how many there are. But we’re not sure if we’ll need to send messages to the compliance service, too. If that happens, we’ll have to rework the trading service to start sending messages to a third queue. In short, if we choose queues, we’re giving up on extensibility.

Image

See what we mean when we say “trade-off analysis”?

Trade-off analysis: Topic edition

What about using topics? Well, the upside is clear—the trading service only delivers messages to a topic, and anyone interested in listening for a message from the trading service simply subscribes to that topic. Compliance wants in? They can simply subscribe: no need to make any changes to the trading service. Low coupling for the win.

Image

But topics have a few downsides, too. For one thing, you can’t customize the message for any particular service—it’s a one-size-fits-all, take-it-or-leave-it proposition. Scaling, too, is one-size-fits-all, since you have only one thing to scale. And anyone can subscribe to the topic without the trading service knowing—which, in some circumstances, is a potential security risk.

Back to the whiteboard!

Image

Sharpen your pencil

Image

Spend a few minutes comparing the results of our trade-off analysis. Notice how both options support some characteristics but trade off on others? Now we’re going to present you with some requirements—see if you can decide if you’d pick queues or topics to support each one.

Requirements
“Security is important to us.” Queues / Topics
“Different downstream services need different kinds of information.” Queues / Topics
“We’ll be adding other downstream services in the future.” Queues / Topics

Images Solution in “Exercise Solution”

The first law of software architecture

Queues or topics? Enough with the suspense already. The answer is— it depends !

What’s important to the business? If security is paramount, we should probably go with queues. Two Many Sneakers is growing by leaps and bounds and has loads of other services interested in its sneaker trades, so extensibility is its biggest priority. That means we should pick the topic option.

Time is also a factor: if we need to get to market quickly, we might pick a simpler architecture (simplicity) over one that offers high availability. (Having an application that guarantees three “nines” of uptime only matters if you have customers, right?)

Image

The key takeaway is that in software architecture, you’ll always be balancing trade-offs. That leads us to the First Law of Software Architecture .

Image

In software architecture, nice, clean lines are rare and there are no “best practices.” Every choice you make will involve many factors—often conflicting ones. The First Law is an important lesson, so take it to heart. Write it down on a sticky note and put it on your monitor. Get a backwards tattoo of it on your forehead so you’ll see it in the mirror! Whatever it takes.

Note

If you find a decision in software architecture that doesn’t have a trade-off, you haven’t looked at it hard enough.

Sharpen your pencil

Image

This time, we’d like you to do some trade-off analysis on your own. We chose messaging as the communication protocol between our trading service and its consumers. Messaging is asynchronous. Choosing between asynchronous and synchronous forms of communication comes with its own set of trade-offs! We’ve given you two whiteboards, one for each form of communication, and we’ve listed a bunch of “-ilities.” We’d like you to consider how each architectural characteristic would work in both contexts. Is this characteristic a pro or a con (or neither) in synchronous communications? What about in asynchronous communications? Place each “-ility” in the appropriate column. Hint: Not all of them apply to this decision. We put the first pro on the whiteboard for you. When you’re done, you can see our answers at the end of the chapter.

Image

Image

Images Solution in “Sharpen your pencil Solution”

there are no Dumb Questions

Q: I’ve heard of the Architecture Tradeoff Analysis Method (ATAM). Is that what you’re talking about?

A: ATAM is a popular method of trade-off analysis. With ATAM, you start by considering the business drivers, the “-ilities,” and the proposed architecture, which you present to the stakeholders. Then, as a group, you run through a bunch of scenarios to produce a “validated architecture.” While ATAM offers a good approach, we believe it comes with certain limitations—one being that it assumes the architecture is static and doesn’t change.

Rather than focusing on the process of ATAM, we prefer to focus on results. The objective of any trade-off analysis should be to arrive at an architecture that best serves your needs. You’ll probably go through the process several times as you discover more and more about the problem and come up with different scenarios.

Another popular approach is the Cost Benefit Analysis Method (CBAM). In contrast to ATAM, CBAM focuses on the cost of achieving a particular “-ility.”

We recommend you look at both methods and perhaps consider combining them—ATAM can help with trade-off analysis, while CBAM can help you get the best return on investment (ROI).

Just remember—the process is not as important as the goal, which is to arrive at an architecture that satisfies the business’s needs.

It always comes back to trade-offs

Some people always pick a particular technique, approach, or tool regardless of the problem at hand. Often they choose something they’ve had a lot of success with in the past. Sometimes they have what we affectionately call “shiny object syndrome,” where they think that some new technology or method will solve all their problems.

Regardless of past achievements or future promises, just remember— for every upside, there’s a downside . The only questions you need to answer are “Will the upsides help you implement a successful application?” and “Can you live with the downsides?”

Whenever someone sings the praises of a certain approach, your response should be: “What are the trade-offs?”

Note

To be clear, we aren’t saying you shouldn’t use new tools and techniques. That’s progress, right? Just don’t forget to consider the trade-offs as you decide.

Making an architectural decision

Debating the pros and cons with your team in front of a whiteboard is fun and all, but at some point, you must make an architectural decision .

We mentioned architectural decisions in Chapter 1 , but let’s dive a little deeper. As you architect and design systems, you will be making lots of decisions, about everything from the system’s overall structure to what tools and technologies to use. So what makes a decision an architectural decision?

Image

In most cases, any choice you make that affects the structure of your system is an architectural decision. Here are a couple of example decisions:

Note

To jog your memory, picking whether you’d like a one- or two-story house would be an architectural decision.

Image

Image

Image

Notice how these decisions act as guides rather than rules. They aid teams in making choices, without being too specific. Most (but not all) of the architectural decisions you’ll make will revolve around the structure of your systems.

Note

As we put it in Chapter 1 : “Architectural decisions serve as guideposts to help development teams understand the constraints and conditions of the architecture.”

What else makes a decision architectural?

Usually, architectural decisions affect the structure of an architecture—are we going with a monolith, or will we leverage microservices? But every so often, you might decide to maintain a particular architectural characteristic. If security is paramount, for example, Two Many Sneakers might make a decision like this:

Image

At other times, you might decide on a specific tool, technology, or process if it affects the architecture or indirectly helps you achieve a particular architectural characteristic. For example:

Image

Everything in this chapter so far has led to this important moment—making an architectural decision. You start with a trade-off analysis. Then you consider the pros and cons of each option in light of other constraints, like business and end user needs, architectural characteristics, technical feasibility, time and budgetary constraints, and even development concerns. Then, finally , you can make a decision.

Geek Note

Image

Michael Nygard, author of the book Release It! (Pragmatic Programmer), defines an architecturally significant decision as “something that has an effect on how the rest of the project will run” or that can “affect the structure, non-functional characteristics, dependencies, interfaces, or construction techniques” of the architecture. To learn more, we recommend reading his blog post, “Documenting Architecture Decisions” ( https://www.cognitect.com/blog/2011/11/15/documenting-architecture-decisions ).

Image

You bring up several good points. It’s important to record our decisions in a more permanent way. In addition, trade-off analysis is an involved process. It’d be a real waste if we lost all that work just because someone got a little hasty with the eraser.

But you make another key observation: while the decision itself is important, why we made that decision might be even more important. Which leads us to...

The second law of software architecture

Making decisions is one of the most important things software architects do.

Let’s say you and your team do a trade-off analysis and conclude that you’re going to use a cache to improve your application’s performance. The result of your analysis is that your system starts using a cache somewhere. The what is easy to spot.

That decision is important, but so are the circumstances in which you made the decision, its impact on the team implementing it, and why , of all the options available to you, you chose what you did.

This leads us to the Second Law of Software Architecture .

Image

You see, future architects (or even “future you”) might be able to discern what you did and even how you did it—but it’ll be very hard for them to tell why you did it that way. Without knowing that, they might waste time exploring solutions you’ve already rejected for good reasons, or miss a key factor that swayed your decision.

This is why we have the Second Law. You need to understand and record the “why” of each decision so it doesn’t get lost in the sands of time.

So how do we go about capturing architectural decisions? We’ll dive into that next.

Architectural decision records (ADRs)

Do you remember everything you did last week? No? Neither do we. This is why it’s important to document stuff—especially the important stuff.

Thanks to the Second Law of Software Architecture, we know we need a way to capture not just the decision, but the reason we made it. Architects use architectural decision records (ADRs) to record such decisions because it gives us a specific template to work with.

Note

We cannot emphasize enough how important keeping these records is.

An ADR is a document that describes a specific architectural decision. You write one for every architectural decision you make. Over time, they’ll build up into an architectural decision log . Remember that architectural decisions form the second dimension to describe your architecture. ADRs are the documentation that supports this dimension.

Image

An ADR has seven sections: Title, Status, Context, Decision, Consequences, Governance, and finally Notes. Every aspect of an architectural decision, including the decision itself, is captured in one of these sections. Let’s take a look, shall we?

Cubicle conversation

Image

Alex: Doing the trade-off analysis between queues and topics took it out of me.

Mara: Me too. Trade-off analysis can be arduous, but I’m glad we got it done. This is a big architectural decision. It’s crucial that we understand the pros and cons of every choice.

Sam: Yeah, yeah. So we decided to use queues, right? Now can we get back to programming?

Mara: Slow down a second. You’re right—we’ve made a decision. Now we should record our decision in an ADR.

Note

Guess what? You’re going to be helping the team write their ADR. Keep an eye out for those exercises

Sam: But why? We already know what we’re going to do. That seems like a lot of work.

Alex: Look, we know why we chose to go with queues. It’s the option that best supports the architectural characteristics we want to maximize in the system, right?

Mara: Correct. But while we know why we made that decision, what about anyone else who might come along and wonder why we chose queues over topics, like future employees? That’s why we should record our thinking.

Sam: I can see that being useful.

Alex: Great! So can we start drafting our ADR?

Writing ADRs: Getting the title right

Every ADR starts with a title that describes the decision. Craft this title carefully. It should be meaningful, yet concise. A good title makes it easy to figure out what the ADR is about, which is especially handy when you’re frantically searching for an answer!

Image

Let’s dive deeper into what a good ADR title looks like. Imagine a team is writing a service that provides surveys to customers. They’ve done a trade-off analysis and have decided to use a relational database to store survey results. Here’s what their ADR title might look like:

Image

The title should consist mostly of nouns. Keep it terse: you’ll have plenty of opportunities to go into detail later. It should describe what the ADR is about, much like the headline of a news article or blog post. Get that right, and the rest will follow.

The title should start with a number—we suggest using three digits, with leading zeros where needed. This allows you to number your ADRs sequentially , starting with 001 for your first ADR, all the way to 999. Every time you add a new ADR, you increment the number. This makes it easy for anyone reading your records to know which decisions came before others.

there are no Dumb Questions

Q: What happens if we end up writing more than 999 ADRs?

A: That’s a lot of ADRs! If that were to happen, you’d need to revise a bunch of titles (and potentially filenames). In our experience, a three-digit prefix is plenty.

Q: Can I reuse an ADR number?

A: Every ADR should get a unique identifier. This makes it easier to reference them without confusion.

Note

More about this when we discuss the Status section.

Exercise

Image

In the following exercises, you’re going to help the team at Two Many Sneakers write an ADR. They’ve decided to use asynchronous messaging, with queues between the trading service and downstream services. Assume this is the 12th ADR the team is writing. What title would you give this ADR? Don’t forget to number it! Use this space to jot down your thoughts. You can see what we came up with at the end of this chapter.

Images Solution in “Exercise Solution”

Writing ADRs: What’s your status?

Great! You’ve settled on a descriptive title. Next, you’ll need to decide on the status of your ADR. The status communicates where the team stands on the decision itself.

But wait—isn’t the point of the ADR to record a decision ? Well, kinda. But making decisions is a process.

ADRs do record architectural decisions, but they also act as documentation , making it easier to share and collaborate. Others might need to look at or even sign off on an ADR. Let’s start by considering the different statuses an ADR can have.

Image

  • Images Request for Comment (RFC)

    Use this status for ADRs that need additional input—perhaps from other teams or some sort of advisory board. Usually, these ADRs affect multiple teams or address a cross-cutting concern like security. An ADR in RFC status is typically a draft, open for commentary and critique from anyone invited to do so. An ADR in RFC status should always have a “respond by” deadline.

    Note

    This is like planning an evening out. You know you’d like to go out and which friends you want to invite, but you hope they’ll suggest a restaurant.

    Note

    You ask everyone to respond by Tuesday so you can make reservations. (The deadline is important, since Ted can never make up his mind about anything.)

  • Images Proposed

    After everyone has a chance to comment, the ADR’s status moves to Proposed. This means the ADR is waiting for approvals. You might edit it or even overhaul the decision if you discover a limitation that makes it a no-go. In other words, you still haven’t made a decision, but you’re getting there.

    Note

    You have a plan for the evening, but you haven’t hit “send” on the invite yet—just in case the weather turns.

  • Images Accepted

    Does exactly what it says on the tin. A decision has been made, and everyone is on board who needs to be. An Accepted status also tells the team tasked with implementing this decision that they can get started.

    Note

    Oh yeah. Everyone has RSVP’d. Time to find a cool outfit!

If there’s no need for feedback from others, you can set the ADR’s status to Accepted as soon as the decision is made. Most ADRs stay at Accepted, but there is one more status to be aware of: Superseded.

You’ve arrived at a decision, which you diligently record in an ADR. Signed, sealed, delivered—you’re done.

But then things change.

Maybe the business is growing and the board decides to focus more on scalability than on time to market. Maybe the company is entering international markets and needs to comply with EU data privacy and retention regulations. Whatever the reason, the decision you made is no longer appropriate. What now?

Well, you write another ADR. The old ADR is superseded by the new one, and you record it as such. Suppose the customer survey team realizes that a relational database is no longer fulfilling their needs, so they do another trade-off analysis and decide to switch to a document store. Here are the titles and statuses of the old and new ADRs:

Image

An accepted ADR can move into Superseded status if a future ADR changes the decision it documents. It’s important for both ADRs to highlight which ADR did the superseding and which ADR has been superseded . This bidirectional linking allows anyone looking at a superseded ADR to quickly realize that it’s no longer relevant, and tells them exactly where to look for details on the new decision. Anyone looking at the superseding ADR can follow the link back to the superseded ADR to understand everything involved in solving that particular problem.

Note

Linking ADRs is an important part of a project’s “memory.” It helps everyone remember what has already been tried.

there are no Dumb Questions

Q: All this superseding and numbering seems overly complicated. Why not just edit the original ADR?

A: We use a three-digit prefix in the ADR title because it helps sequence things. Let’s say ADR 007 no longer applies to your situation, but you’ve made a bunch of architectural decisions in the meantime. The last ADR in your architectural decision log is ADR 013.

Now you need to reevaluate ADR 007. Say you choose to edit it, as opposed to superseding it with ADR 014. What would happen?

Chronologically speaking, you amend ADR 007 after accepting ADR 013. But if someone tried to follow the decision process by reading the ADRs, they’d be seeing them in the wrong order! Readers might think that the new decision came first. It wouldn’t convey that you made one decision and then had to change it for some reason. Giving it a new number makes it clear that the old ADR 007 was no longer relevant after ADR 013. Confused yet?

Q: So you’re telling me that an Accepted ADR is immutable : once accepted, it is not permitted to change. Is that right?

A: Look at you! That’s exactly it. Except for when the status of an ADR goes from Accepted to Superseded, a decision recorded in an ADR is immutable. Sure, you might edit the ADR to include additional information, but for the most part, other than the status, things shouldn’t change much.

Exercise

Image

In the previous exercise, you hashed out the title of Two Many Sneakers’ ADR about using queues for messaging. Let’s say you get the green light. Write down the title you chose in the space below and give your ADR a status:

  • Title: _________________________________________________________________________

  • Status: _________________________________________

Three months later:

Whoops! The requirements have changed. Your latest trade-off analysis reveals that topics would be a better fit. Everyone has signed off on this, so you need to supersede your ADR with a new ADR. This is the 21st ADR your team has worked on. Write down the title and the new status of the old ADR:

  • Title: _________________________________________________________________________

  • Status: _________________________________________

Now write down the title and status of the newly introduced ADR:

  • Title: _________________________________________________________________________

  • Status: _________________________________________

Images Solution in “Exercise Solution”

Writing ADRs: What’s your status? (recap)

There’s a lot going on with ADR statuses, so we’ve created a handy visualization to help you out.

Image

Writing ADRs: Establishing the context

Context matters. Every decision you’ve ever made, you made within a certain context and with certain constraints. When you chose what to have for breakfast this morning, the context might have included how hungry you were, how your body felt, your lunch plans, and whether you’re trying to increase your fiber intake. It’s no different for software architecture.

Image

The Context section in the ADR template is your place to explain the circumstances that drove you to make the decision the ADR is capturing. It should also capture any and all factors that influenced your decision. While technological reasons will usually find their way onto this list, it’s not unusual to include cultural or political factors to help the reader understand where you’re coming from.

Image

Sharpen your pencil

Image

Continue building out the ADR for Two Many Sneakers. Use the space below to write a Context section for the team’s decision to use queues for communication between the trading service and other services. (Then compare it with our take at the end of this chapter.)

Images Solution in “Sharpen your pencil Solution”

there are no Dumb Questions

Q: What about all that time and effort I spent on the whiteboard? Is that part of the context?

A: If you need to document your trade-off analysis, we suggest you introduce a new section called “Alternatives.” In it, list all the alternatives you considered, followed by your lists of pros and cons.

Using a separate section to detail the trade-off analysis delineates it cleanly and avoids cluttering the Context section.

Writing ADRs: Communicating the decision

We’ve finally arrived at the actual decision. Let’s start by looking at the customer survey team’s completed Decision section:

Image

Image

If this ADR’s status is RFC or Proposed, the decision hasn’t been made (yet). Even so, the Decision section starts by clearly expressing the decision being made . The tone of the writing should reflect that. It’s best to use an authoritative voice when stating the decision, with active phrases like “we will use” (as opposed to “we believe” or “we think”).

The Decision section is also the place to explain why you’re making this decision, paying tribute to the Second Law of Software Architecture: “Why is more important than how.” Future you, or anyone else who reads the ADR, will then understand not just the decision but the justification for it.

Note

In the Context section, you explained why this decision was on the table. The Decision section, which immediately follows it, explains the decision itself. Together, they allow the reader to frame the decision correctly.

Note

This is also a great place to list others who signed off on this decision. For example, “The marketing department requires...” is an example of CYA.

Note

“Cover Your Assets”! :)

Watch it!

Image

The ADR is not an opinion piece

Remember that the ADR is not a place for anyone’s opinions on the state of things. It’s easy to slip into that mode, especially when justifying a decision. Even when explaining context, it can sometimes be hard to stay objective.

Treat an ADR like a journalist treats a news article—stick to the facts and keep your tone neutral.

Exercise

Image

It’s time for you to write the Decision section of the ADR for Two Many Sneakers. Here are the main factors the team considered when making their decision:

  • Queues allow for heterogeneous messages.

  • Security is an important architectural characteristic for the stakeholders.

We’ve given you some space to write out a Decision section, including the corresponding justification. This section should answer the question, “Why queues?” Hint: Be sure to focus on the decision and the “why.” See the solution at the end of the chapter for our own take.

Note

Feel free to glance back at the trade-off analysis we did earlier in the chapter to refresh your memory.

Images Solution in “Sharpen your pencil Solution”

there are no Dumb Questions

Q: I’m not entirely clear on the difference between the context and the “justification” we provide in the Decision section. Aren’t those the same thing?

A: Maybe an example will help. Say it’s your best friend’s birthday, and you and a few others decide to go out to a fancy dinner to celebrate. That’s the context —the circumstances surrounding the decision you have to make.

Before you decide on the details, you might make a list of possible restaurants (the alternatives available to you), thinking about how well the cuisines they offer match everyone’s preferences. This would be akin to a trade-off analysis.

You pick a pan-Asian bistro: that’s the decision . You choose that particular restaurant because its menu has vegetarian and gluten-free options, and it allows anyone with dietary restrictions to make substitutions. That’s the justification for your decision.

Writing ADRs: Considering the consequences

Every decision has consequences . Did you work out extra hard yesterday? If so, you might be sore this morning. (But maybe a little bit proud of yourself, too!)

Image

It’s important to realize the consequences—good and bad—of architectural decisions and document them. This increases transparency by ensuring that everyone understands what the decision entails, including the team(s) affected by it. Most importantly, it allows everyone to assess whether the decision’s positive consequences will outweigh its negative consequences.

The consequences of an ADR can be limited in scope or have huge ramifications. Architectural decisions can affect all kinds of things—teams, infrastructure, budgets, even the implementation of the ADR itself. Here’s an incomplete list of questions to ask:

  • How does this ADR affect the implementing team? For instance, does it change the algorithms? Does it make testing harder or easier? How will we know when we’re “done” implementing it?

  • Does this ADR introduce or decommission infrastructure? What does that entail?

  • Are cross-cutting concerns like security or observability affected? If so, what effects will that have across the organization?

  • How will the decision affect your time and budget? Does it introduce costs or save money? Will it take arduous effort to implement or make things easier?

    Note

    Time and money are big—be sure to think this one through!

    Note

    Of course, the ADR might make things simpler and more cost-effective. If so, that’s definitely worth highlighting.

  • Does the ADR introduce any one-way paths? (For example, using queues means we can’t control the order of messages.) If so, elaborate on this.

Collaborating with others is a great way to make sure your assessment is thorough. No matter how hard you think through the consequences of the ADR, you’re likely to miss a few things; multiple perspectives will reveal more potential consequences. Here’s a sample Consequences section:

Image

Sharpen your pencil

Image

Help the Two Many Sneakers team iron out the Consequences section of their ADR. Here are a few things to think about:

  • Images A queue introduces a new piece of infrastructure.

  • Images The queues themselves will probably need to be highly available.

    Note

    There are no right or wrong answers, but if you’d like to see how we approached this, glance at the solution at the end of the chapter.

  • Images Queues mean a higher degree of coupling between services.

Images Solution in “Sharpen your pencil Solution”

Brain Power

Image

Think about an architectural decision made in your current project, or one you’ve worked on in the past. It might be programming language used, the application’s structure, or even the choice of database. Can you think of at least two intended consequences and two unintended consequences of that decision?

Writing ADRs: Ensuring governance

Have you ever made a New Year’s resolution that fizzled out before the end of February? Maybe you joined a gym, only to end up paying but never working out? Us too. A decision is only good if you act on it, and if you don’t accidentally stray away from it in the future.

Image

Sure, you and your team spent a bunch of time analyzing trade-offs and writing an ADR to record the decision. Now what? How do you ensure that the decision is correctly implemented—and that it stays that way?

This is the role of the Governance section, which is vital in any ADR. Here, you outline how you’ll ensure that your organization doesn’t deviate from the decision—now or in the future. You could use manual techniques like pair programming or code reviews, or automated means like specialized testing frameworks.

Note

These two sections aren’t part of the standard ADR template, but we think they add a lot of value.

Note

If the word “governance” conjures up ideas of regulatory compliance, well, this isn’t that.

Note

One of your authors has written a book called “Building Evolutionary Architectures” that shows you how to use “fitness functions” for architectural governance. Be sure to pick up a copy. (After you’re done with this book, of course!)

Image

Writing ADRs: Closing notes

The Notes section contains metadata about the ADR itself. Here’s a list of fields we like to include in our ADRs:

  • Original author

  • Approval date

  • Approved by

  • Superseded date

  • Last modified date

  • Modified by

  • Last modification

Note

This section is handy even if the tool you use to store your ADRs automatically records things like creation and modification dates. Yes, including this information may be repetitive, but making it part of the ADR makes it easier to discover.

Exercise

Image

Let’s bring it all together! You’ve been working piecemeal on the ADR for the Two Many Sneakers team. We’d like you to flip back to the past few exercises and copy your ADR sections onto this page to create a full ADR. We’ve given you the section titles—all you have to do is fill ’em out. (Assume the status to be “Accepted.”) You can find our version at the end of the chapter.

Image

Images Solution in “Exercise Solution”

there are no Dumb Questions

Q: I really like the ADR template. But where am I supposed to store my ADRs?

A: There are lots of options—it all depends on what you and your team are comfortable with, and who else might be interested in reading or contributing to the ADRs.

One option is to store ADRs in plain-text files (or maybe Markdown or AsciiDoc files) in a version-control system like Git. This way, there’s a commit history showing any changes to the ADRs. The downside is that nondevelopers don’t always know how to access version-controlled documents. If you do choose to store your ADRs this way, we recommend keeping them in a separate repository (as opposed to stuffing them in with your source code). You’ll thank us later.

Alternatively, you could use a wiki. Most wikis use a WYSIWYG (“what you see is what you get”) editor, so they’re accessible to more people. Just be sure that your choice of wiki can track changes. You wouldn’t want someone to edit an ADR accidentally without everyone knowing.

Whatever you choose, make sure it’s easy to add, edit, and search for ADRs. We’ve seen too many honest efforts at recording ADRs die just because no one could find the ADRs again if their lives depended on it.

Q: My whole team loves Markdown. (Plain text for the win!) Any advice on file naming conventions?

A: Recall that ADR titles have a three-digit prefix, followed by a very succinct description of the ADR. If you store your ADRs as plain-text files, we recommend using the title as your filename, including the prefix. For example, an ADR with the title “042: Use queues between the trading and downstream services” should be stored in a file named 042-use-queues-between-the-trading-and-downstream-services.md. We like using all lowercase letters, which avoids any confusion between different operating systems. Replace spaces with hyphens to avoid whitespace.

This forces you to come up with good titles! And the three-digit prefix means you can simply sort the files in a folder by name to put them in the right order.

Q: Can you recommend any tools that make it easier to write and manage ADRs?

A: Oh, sure! There are many options, from command-line tools to language-specific tools that allow you to record ADRs directly in your source code. You can see a list of available tools at https://adr.github.io/#decision-capturing-tools .

Most third-party tools make assumptions about the format of the ADR—perhaps they generate Markdown files or store the files in a specific directory structure. Test-drive a tool a few times to get a feel for it.

Finally, some age-old advice: keep it simple, silly. We suggest you start by writing out ADRs without any complicated tooling or automation. Get a sense of what works best for your team. Then, as your needs grow, go find a tool that fits those needs.

Q: Do ADRs always belong to a single project, or can they affect multiple projects and teams? How about the whole organization?

A: Yes, yes, and yes. ADRs can be as narrow or as broad as you’d like them to be. Some ADRs are project-specific, affecting only one team. Other ADRs affect many or all teams in an organization. At the online retailer Amazon, there’s an ADR affectionately referred to as “the Jeff Bezos API mandate.” It records a decision that company founder Jeff Bezos once made: that all services within Amazon can only talk to other services via an API. Naturally, this affected the entire organization—no small feat, given Amazon’s size.

Most cross-project or cross-team ADRs require a lot of collaboration, and often the blessing of a central architecture review board. Such ADRs tend to affect cross-cutting concerns, like how services should communicate with one another or which data transfer protocol to use. ADRs related to security or regulatory compliance often cut across multiple teams or a whole organization.

The benefits of ADRs

We hope we’ve convinced you by now that recording your decisions in ADRs need not be a long, arduous process. We really like the format we’ve shown you in this chapter, but feel free to tweak or modify it.

Is recording architectural decisions really that important? We certainly think so! There are tons of benefits to recording these decisions—not just for you and your team, but for your entire organization. Let’s quickly recap.

Image

Watch it!

Image

Keep the ADR process as frictionless as possible

It’s tempting to add sections to the ADR template in the hope of being comprehensive. While that’s a noble goal, it adds work. If you keep “feeding the beast,” the documentation process gets harder. That can discourage people, and some might stop writing ADRs altogether.

Focus on concision and brevity. Keep it simple. You’ll thank us later.

Two Many Sneakers is a success

The team at Two Many Sneakers is ecstatic. Their customers love getting real-time notifications about new offerings in the app, and the improved analytics are giving the security team the information they need to sniff out any and all sneaker scams from a mile away.

Image

Grokking the two laws of software architecture will serve you well. Now you know that there are no “best practices” in software architecture—just trade-offs. It’s up to you (and your team) to find the most viable and best-fitting option. And don’t forget to record your decision in an ADR!

Onward and upward.

Bullet Points

  • There is nothing “static” about architecture. It’s constantly changing and evolving.

  • Requirements and circumstances change. It’s up to you to modify your architecture to meet new goals.

  • For every decision, you will be faced with multiple solutions. To find the best (or least worst), do a trade-off analysis . This collaborative exercise helps you identify the pros and cons of every possible option.

  • The First Law of Software Architecture is: Everything in software architecture is a trade-off.

  • The answer to every question in software architecture is “it depends.” To learn which solutions are best for your situation, you’ll need to identify the top priorities and goals . What are the requirements? What’s most important to your stakeholders and customers? Are you in a rush to get to market, or hoping to get things stable in growth mode?

  • The product of a trade-off analysis is an architectural decision : one of the four dimensions needed to describe any architecture.

  • An architectural decision involves looking at the pros and cons of every choice in light of other constraints—such as cultural, technical, business, and customer needs—and choosing the option that serves these constraints best.

  • Making an architectural decision isn’t just about choosing; it’s also about why you’re choosing that particular option.

  • The Second Law of Software Architecture is: Why is more important than how.

  • To formalize the process of capturing architectural decisions, use architectural decision records (ADRs). These documents have seven sections: Title, Status, Context, Decision, Consequences, Governance, and Notes.

  • Over time, your ADRs will build into a log of architectural decisions that will serve as the memory store of your project.

  • An ADR’s title should consist of a three-digit numerical prefix and a noun-heavy, succinct description of the decision being made.

  • An ADR can be assigned one of many statuses , depending on the kind of ADR and its place in the decision workflow.

  • Once all parties involved in the decision sign off on the ADR, its status becomes Accepted.

  • If a future decision supplants an Accepted ADR, you should write a new ADR. The supplanted ADR’s status is marked as Superseded and the new ADR becomes Accepted.

  • The Context section of an ADR explains why the decision needed to be made to begin with.

  • The Decision section documents and justifies the actual decision being made. It always includes the “why.”

  • The Consequences section describes the decision’s expected impact, good and bad. This helps ensure that the good outweighs the bad, and aids the team(s) implementing the ADR.

  • The Governance section lists ways to ensure that the decision is implemented correctly and that future actions do not stray away from the decision.

  • The final section is Notes , which mostly records metadata about the the ADR itself—like its author and when it was created, approved, and last modified.

  • ADRs are important tools for abiding by the Second Law of Software Architecture, because they capture the “why” along with the “what.”

  • ADRs are necessary for building institutional knowledge and helping teams learn from one another.

“Two Laws” Crossword

Image

Think you’ve mastered the two laws of software architecture? Why don’t you document your knowledge by completing this crossword?

Image

Across

2. Two Many _____

4. Topics use a fire-and-_____ system

5. A new ADR can _____ an old one

7. You can list pros and cons on a _____board

8. You should record every architectural _____ you make

10. Documents made up of seven sections (abbr.)

11. Heterogeneous

13. Important architectural characteristic for a fast-growing business

15. “Everything in software architecture is a trade-off” is the _____ _____ of software architecture (two words)

18. Examples of messaging mechanisms include queues and _____

19. Best tone to use when writing an ADR

20. If you’re too excited about a new tool, you might have _____ Object Syndrome

Down

1. Topics can be independently _____

3. An architectural characteristic that’s especially important for financial transactions

5. Architects are responsible for making architecturally _____ decisions

6. ADR section that tells you why a decision needed to be made

9. High or low interdependence

12. Short way to say “not at the same time”

14. Two Many Sneakers’ mobile app communicates with the trading _____

16. More important than how, according to the Second Law

17. The _____ of an ADR might be Accepted

Images Solution in ““Two Laws” Crossword Solution”

From “Exercise”

Exercise Solution

Image

Which of the following architectural characteristics stand out as important for this particular problem? Hint: There are no right answers here, because there is a lot we don’t know or aren’t sure of yet. Take your best guess—here are our thoughts:

Image

From “Sharpen your pencil”

Sharpen your pencil

Image

Spend a few minutes comparing the results of our trade-off analysis. Notice how both options support some characteristics but trade off on others? Now we’re going to present you with some requirements—see if you can decide if you’d pick queues or topics to support each one. Here are our answers:

Image

From “Sharpen your pencil”

Sharpen your pencil Solution

Image

This time, we’d like you to do some trade-off analysis on your own. We chose messaging as the communication protocol between our trading service and its consumers. Messaging is asynchronous. Choosing between asynchronous and synchronous forms of communication comes with its own set of trade-offs! We’ve given you two whiteboards, one for each form of communication, and we’ve listed a bunch of “-ilities.” We’d like you to consider how each architectural characteristic would work in both contexts. Is this characteristic a pro or a con (or neither) in synchronous communications? What about in asynchronous communications? Place each “-ility” in the appropriate column. Hint: Not all of them apply to this decision. You’ll find our answers below:

Image

Image

From “there are no Dumb Questions”

Exercise Solution

Image

In the following exercises, you’re going to help the team at Two Many Sneakers write an ADR. They’ve decided to use asynchronous messaging, with queues between the trading service and downstream services. Assume this is the 12th ADR the team is writing. What title would you give this ADR? Don’t forget to number it! Here’s what we came up with:

  • 012: Use of queues for asynchronous messaging between order and downstream services

From “there are no Dumb Questions”

Exercise Solution

Image

In the previous exercise, you hashed out the title of Two Many Sneakers’ ADR about using queues for messaging. Let’s say you get the green light. Write down the title you chose in the space below and give it a status. Here’s ours:

Image

Three months later:

Whoops! The requirements have changed. Your latest trade-off analysis reveals that topics would be a better fit. Everyone has signed off on this, so you need to supersede your ADR with a new ADR. This is the 21st ADR your team has worked on. Write down the title and the new status of the old ADR:

Image

Now write down the title and status of the newly introduced ADR. Here’s ours:

Image

From “Sharpen your pencil”

Sharpen your pencil Solution

Image

Continue building out the ADR for Two Many Sneakers. Use the space below to write a Context section for the team’s decision to use queues for communication between the trading service and other services. Here’s our take:

The trading service must inform downstream services (namely the notification and analytics services, for now) about new items available for sale and about all transactions. This can be done through synchronous messaging (using REST) or asynchronous messaging (using queues or topics).

From “Exercise”

Exercise Solution

Image

It’s time for you to write the Decision section of the ADR for Two Many Sneakers. Here are the main factors the team considered when making their decision:

  • Queues allow for heterogeneous messages.

  • Security is an important architectural characteristic for the stakeholders.

We’ve given you some space to write out a Decision section, including the corresponding justification. This section should answer the question, “Why queues?” Hint: Be sure to focus on the decision and the “why.” There are no right answers, but here’s what we came up with:

We will use queues for asynchronous messaging between the trading and downstream services.

Using queues makes the system more extensible, since each queue can deliver a different kind of message. Furthermore, since the trading service is acutely aware of any and all subscribers, adding a new consumer involves modifying it—which improves the security of the system.

From “Sharpen your pencil”

Sharpen your pencil Solution

Image

Help the Two Many Sneakers team iron out the Consequences section of their ADR. Here are a few things to think about:

  • Images A queue introduces a new piece of infrastructure.

  • Images The queues themselves will probably need to be highly available.

  • Images How do queues affect coupling between components?

Queues mean a higher degree of coupling between services.

We will need to provision queuing infrastructure. It will require clustering to provide for high availability.

If additional downstream services (in addition to the ones we know about) need to be notified, we will have to make modifications to the trading service.

Note

Here’s our take.

From “Exercise”

Exercise Solution

Image

Let’s bring it all together! You’ve been working piecemeal on the ADR for the Two Many Sneakers team. We’d like you to flip back over the past few exercises and copy your ADR sections onto this page to create a full ADR. We’ve given you the section titles—all you have to do is fill ’em out. (Assume the status to be “Accepted.”) Here’s our version:

Image

“Two Laws” Crossword Solution

Image

From ““Two Laws” Crossword”

Image