Book Image

Software Architecture Patterns for Serverless Systems

By : John Gilbert
Book Image

Software Architecture Patterns for Serverless Systems

By: John Gilbert

Overview of this book

As businesses are undergoing a digital transformation to keep up with competition, it is now more important than ever for IT professionals to design systems to keep up with the rate of change while maintaining stability. This book takes you through the architectural patterns that power enterprise-grade software systems and the key architectural elements that enable change (such as events, autonomous services, and micro frontends), along with showing you how to implement and operate anti-fragile systems. First, you’ll divide up a system and define boundaries so that your teams can work autonomously and accelerate innovation. You’ll cover low-level event and data patterns that support the entire architecture, while getting up and running with the different autonomous service design patterns. Next, the book will focus on best practices for security, reliability, testability, observability, and performance. You’ll combine all that you've learned and build upon that foundation, exploring the methodologies of continuous experimentation, deployment, and delivery before delving into some final thoughts on how to start making progress. By the end of this book, 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.
Table of Contents (99 chapters)
Preface
1
Section 1: Establishing an Architectural Vision
Free Chapter
2
Chapter 1: Architecting for Innovation
3
Continuously delivering business value
4
Taking control of lead time
5
Dissecting integration styles
6
Enabling autonomous teams with autonomous services
7
Summary
8
Chapter 2: Defining Boundaries and Letting Go
9
Building on SOLID principles
10
Thinking about events first
11
Dividing a system into autonomous subsystems
12
Decomposing a subsystem into autonomous services
13
Dissecting an autonomous service
14
Governing without impeding
15
Summary
16
Section 2: Dissecting the Software Architecture Patterns
17
Chapter 3: Taming the Presentation Tier
18
Zigzagging through time
19
Breaking up the frontend monolith
20
Dissecting micro frontends
21
Designing for offline-first
22
Securing the user experience
23
Observing real user activity
24
Summary
25
Chapter 4: Trusting Facts and Eventual Consistency
26
Living in an eventually consistent world
27
Publishing to an event hub
28
Dissecting the Event Sourcing pattern
29
Processing event streams
30
Designing for failure
31
Optimizing throughput
32
Observing throughput
33
Accounting for regional failover
34
Summary
35
Chapter 5: Turning the Cloud into the Database
36
Escaping data's gravity
37
Embracing data life cycle
38
Turning the database inside out
39
Dissecting the CQRS pattern
40
Keeping data lean
41
Implementing idempotence and order tolerance
42
Modeling data for operational performance
43
Leveraging change data capture
44
Replicating across regions
45
Observing resource metrics
46
Redacting sensitive data
47
Summary
48
Chapter 6: A Best Friend for the Frontend
49
Focusing on user activities
50
Dissecting the Backend for Frontend (BFF) pattern
51
Choosing between GraphQL and REST
52
Implementing different kinds of BFF services
53
Securing a BFF in depth
54
Leveraging multiple regions
55
Observing BFF metrics
56
Optimizing BFF performance
57
Summary
58
Chapter 7: Bridging Intersystem Gaps
59
Creating an anti-corruption layer
60
Dissecting the External Service Gateway pattern
61
Integrating with third-party systems
62
Integrating with other subsystems
63
Integrating across cloud providers
64
Integrating with legacy systems
65
Providing an external API and SPI
66
Tackling common data challenges
67
Managing shared secrets
68
Addressing multi-regional differences
69
Summary
70
Chapter 8: Reacting to Events with More Events
71
Promoting inter-service collaboration
72
Dissecting the Control Service pattern
73
Orchestrating business processes
74
Employing the Saga pattern
75
Calculating event-sourcing snapshots
76
Implementing CEP logic
77
Leveraging ML for control flow
78
Implementing multi-regional cron jobs
79
Summary
80
Section 3: Putting Everything in Motion
81
Chapter 9: Choreographing Deployment and Delivery
82
Optimizing testing for continuous deployment
83
Focusing on risk mitigation
84
Achieving zero-downtime deployments
85
Planning at multiple levels
86
Turning the crank
87
Summary
88
Chapter 10: Don't Delay, Start Experimenting
89
Gaining trust and changing culture
90
Funding products, not projects
91
Dissecting the Strangler pattern
92
Addressing event-first concerns
93
Poly everything
94
Summary
95
Why subscribe?
96
Other Books You May Enjoy
97
Packt is searching for authors like you
98
Share Your Thoughts

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:

  1. Install Node Version Manager (https://github.com/nvm-sh/nvm) or (https://github.com/coreybutler/nvm-windows)
  2. Install the latest version of Node.js with nvm install node
  3. 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)
  4. Download the templates: (https://github.com/jgilbert01/aws-lambda-stream/tree/master/templates) and (https://github.com/jgilbert01/micro-frontend-template)
  5. 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.

Resource icon legend

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 [email protected] 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 [email protected] 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.