Preface
Welcome to the book Software Architecture Patterns for Serverless Systems! Our industry has been searching for a silver bullet that allows us to quickly implement high-quality software. While there has been no single development that helps us do this, there has been the culmination of many developments that when brought together in the right combination help us to drive down lead time and continuously deliver business value.
Lean methods, DevOps practices, and the cloud have played a significant role in helping us to continuously deliver high-quality solutions. Now it is our software itself that has become the bottleneck that impedes our ability to deliver. So my goal for this book is to show how to architect systems that enable change and system evolution. This is a comprehensive reference guide to designing architecture and implementing proven practices for delivering business value in a dynamic environment.
This book shows how the serverless-first mindset empowers autonomous teams and how the event-first approach creates an inversion of responsibility that allows us to create enterprise-scale serverless systems. You will learn how to apply the SOLID principles to define a system architecture with well-defined boundaries and then fortify these boundaries with autonomous services and autonomous subsystems. Add in micro frontends and finally, you'll be able to architect your own event-driven, serverless systems that are ready to adapt and change so that you can deliver value at the pace needed by your business.
To get the most out of this book, be prepared with an open mind to discover why serverless is different. Serverless forces us to rewire how we reason about systems. It tests all our preconceived notions of software architecture. I have personally found delivering serverless solutions to be, by far, the most fun and satisfying. So, be prepared to have a lot of fun building serverless systems.
Who this book is for
This book is for software architects and aspiring software architects who want to learn about different patterns and best practices to design better software. Intermediate-level experience in software development and design is required. Beginner-level knowledge of the cloud will also be beneficial.
What this book covers
Chapter 1, Architecting for Innovation, here architects will learn that their job is to facilitate change and that their architecture must enable change. We survey the forces that impact lead time and look at the history of different integration styles to see how these influence the architectural decisions behind all the design patterns. Then we introduce autonomous services and the CPCQ flow and enumerate the set of concepts that enable teams to drive down lead times and continuously deliver business value.
Chapter 2, Defining Boundaries and Letting Go, is where architects begin to divide and conquer the problem domain. An architect will learn how to apply SOLID principles and event-first thinking to define architectural boundaries by dividing a system into autonomous subsystems and those subsystems into autonomous services. They will also learn the importance of continuous governance and how to rely on automation, observability, and key performance indicators to assert the performance of individual teams and to perpetuate an architectural feedback loop.
Chapter 3, Taming the Presentation Tier, addresses the challenges at the presentation tier and provides modern solutions, such as micro frontends, offline-first techniques, and more.
Chapter 4, Trusting Facts and Eventual Consistency, covers the foundational patterns that turn events into facts and support asynchronous inter-service communication, such as the event hub, systemwide event sourcing, and event stream processing.
Chapter 5, Turning the Cloud into the Database, covers the core data patterns that fight data gravity by turning the database inside out and spreading it out along the phases of the data life cycle, including Command Query Responsibility Segregation (CQRS) and Change Data Capture (CDC).
Chapter 6, A Best Friend for the Frontend, covers the Backend for Frontend pattern that supports end-user activities and micro applications throughout the data life cycle. It also covers practices such as security and multi-regional deployments.
Chapter 7, Bridging Intersystem Gaps, covers that External Service Gateway pattern that supports interactions with external systems and creates an anti-corruption layer that protects the system from everything outside the system, including third-party systems, legacy systems, other autonomous subsystems, and more.
Chapter 8, Reacting to Events with More Events, covers the Control Service pattern that supports business process orchestration, sagas, complex event processing, machine learning, and more.
Chapter 9, Choreographing Deployment and Delivery, describes how to decouple deployment from release so that teams can continuously deploy and deliver with zero downtime. It covers the core concepts of backward compatibility and quality assurance.
Chapter 10, Don't Delay, Start Experimenting, provides thoughts on how to start making forward progress toward the architectural vision provided throughout the book. It addresses some of the myths and anti-patterns that keep teams from getting off the ground and covers various hurdles and impediments that architects must confront.
To get the most out of this book
To follow along and experiment with the templates provided with this book you will need to configure your development environment according to these steps:
- Install Node Version Manager (https://github.com/nvm-sh/nvm) or (https://github.com/coreybutler/nvm-windows)
- Install the latest version of Node.js with
nvm install node
- Create an AWS account (https://aws.amazon.com/free) and configure your credentials for the Serverless Framework (https://www.serverless.com/framework/docs/providers/aws/guide/credentials)
- Download the templates: (https://github.com/jgilbert01/aws-lambda-stream/tree/master/templates) and (https://github.com/jgilbert01/micro-frontend-template)
- Run the project scripts, such as:
$ npm ci $ npm test $ npm run test:int $ npm run dp:stg:e
Download the color images
We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here:
https://static.packt-cdn.com/downloads/9781800207035_ColorImages.pdf
Conventions used
There are a number of text conventions used throughout this book.
Code in text
: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Define the functions
in the serverless.yml
file."
A block of code is set as follows:
functions: trigger: handler: src/trigger/index.handle events: - stream: type: dynamodb arn: Fn::GetAtt: [ EntitiesTable, StreamArn ]
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
import { fromDynamodb, ... } from 'aws-lambda-stream'; export const handler = async (event) => fromDynamodb(event) .map(toEvent) .through(publish({ parallel:4, batchSize: 10 })) .through(toPromise);
Tips or important notes
Appear like this.
There is a concise diagramming convention used throughout this book. Serverless services have multiple resources, which can clutter diagrams with a lot of connecting arrows. The following sample diagram demonstrates how we minimize the number of arrows by placing related resources adjacent to each other so that they appear to touch. The nearest arrow implies the flow of execution or data. In this sample diagram, the arrow on the left indicates that the flow moves through the API gateway to a function and into the database, while the arrow on the right indicates the flow of data out of the database stream to a function and into the event bus. These diagrams are created using Cloudcraft (https://cloudcraft.co).
The following table provides a legend of the most common icons used in the diagrams throughout the book.
The software architecture patterns in this book are cloud provider agnostic. However, I use AWS to implement the examples and AWS-specific icons in the diagrams. The preceding table enumerates various cloud provider resources that you could use to implement these patterns on the major cloud providers.
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at customercare@packtpub.com and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Share Your Thoughts
Once you've read Software Architecture Patterns for Serverless Systems, we'd love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we're delivering excellent quality content.