Patterns and practices for an enterprise-scale adoption of serverless!

SheenBrisals 105 views 107 slides Sep 06, 2024
Slide 1
Slide 1 of 107
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101
Slide 102
102
Slide 103
103
Slide 104
104
Slide 105
105
Slide 106
106
Slide 107
107

About This Presentation

As an evolution of the cloud, serverless—a technical concept and an ecosystem—extends cloud capabilities to enable us to rapidly build and deliver modern business capabilities.

Unlike a successful start-up growing fast using serverless technology, enterprise adoption is often challenging. With ...


Slide Content

Patterns and Practices for Developing Enterprise-Scale Applications with Serverless! Sheen Brisals Technologist, Author, AWS Serverless Hero

Engineering Leader O’Reilly Author AWS Serverless Hero Sheen Brisals sheen- brisals sheenbrisals sbrisals.medium.com #TheServerlessBook tinyurl.com/2ncnx2u4

Agenda 01 An Intro to Serverless 02 Complexities of Modern Systems 03 Problem Decomposition 04 Patterns 05 Practices

The History of Serverless

Mainframes Virtual Machines Cloud Services

1950s 1960s 1972 1990s 1996 2000s Mainframes Galactic Network Virtual Machine Operating System Virtual Machines VPNs Cloud Computing term Amazon work on IaaS

2004 2006 2008 2012 2014 2019 Amazon SQS beta Amazon EC2 Amazon S3 Google App Engine Serverless term appears! AWS Lambda Amazon EventBridge

We are just getting started with serverless. It has decades of life in front of it! —Jeff Barr, VP & Chief Evangelistic, AWS

Understanding Serverless

Serverless Pay for compute & storage Auto scalable & highly available Cloud computing model Scale to zero & low cost No server management for you Characteristics Characteristics

Serverless Ecosystem of managed services Ideal for iterative development Optimization at granular level Engineering diversity in teams Deeper level security & data privacy Benefits Benefits

Individuality and granularity at service resource level

Source Destination Data bucket Function 21 SQS queue 2 Function 22 Function 11 SQS queue 1 Function 12 Function 31 SQS queue 3 Function 32 Price changes Product reviews Low latency Low cost Optimization at depth – cost, performance, sustainability

Serverless Control Suitability Quota Cost Timeouts Considerations Considerations

Serverless is more than just a technology… It is more than FaaS , Frameworks, and Architecture blueprints!

The Serverless Ecosystem

An ecosystem is a geographic area where plants, animals, and other organisms, as well as weather and landscape, work together to form a bubble of life. —NationalGeographic.org

This Photo by Unknown Author is licensed under CC BY-SA-NC

Cloud platform Architecture Managed Cloud services Infrastructure definition Development and test tools Repository and pipelines Observability tools Best practices On-demand scaling FaaS Sustainability Scale to zero Pay per use Event driven Deeper security Granularity High availability Builders and stakeholders

A serverless application is an event-driven orchestration of managed services knitted with infrastructure code that brings the best business value!

Complexities of Modern Systems

Modern systems require… Scalability Extendibility Observability Sustainability Reliability Recoverability Picture credit AWS

Some technologies are complex by nature. Often, we build complexity with technology.

Complexity in software systems Accumulated Distributed Monolith Macroservice Lambdalith

Complexity in software systems Monolith Macroservice Lambdalith Accumulated Distributed Simplicity Complexity visible hidden Simplicity Complexity visible hidden

Distributed Teams

Distributed complexity exists… Scalability Extendibility Observability Sustainability Reliability Recoverability Incremental & Iterative dev Automated pipelines Release anytime any day Alert & alarm system issues Recover from failures Fast flow & team velocity Business, Developmental, and Operational needs

Tangled architecture

Problem Decomposition

The most fundamental problem in computer science is problem decomposition : how to take a complex problem and divide it into pieces that can be solved independently.

Glitz & Glamour On screen Hard work & Complexity Behind the Scene

How do film-makers confront complexity ?

Film Interval Intro/title End/credits First Half Second Half

Film Interval Intro/title End/credits Scenes Scenes

I just don’t think it’s that simple. Nothing is. Everything is, when you break it down !

Set Pieces

A set piece is a scene or sequence of scenes whose execution requires logistical planning. Developing a set piece requires planning and execution , but can be rehearsed in advance, completed independently , and brought together.

Characteristics of a set piece A set piece is part of a whole (vision) The focus is on a set piece Planning is essential. Rehearsing or testing is necessary Work on set pieces can progress in parallel All the pieces brought together to make the whole

Film Interval Intro/title End/credits Scenes Scenes Parts Vision Focus Problem Pieces Whole

Decomposition Patterns

Org anization patterns It’s not a book. It’s an industry!

Domain: Insurance Domain: Ecommerce Domains Org anization patterns

Products Customer Org anization patterns Domains Subdomains

Bounded Context Bounded Context Bounded Context Bounded Context Rewards Org anization patterns Domains Subdomains Bounded contexts

Team Patterns Organize teams for autonomy and flow

Team Patterns Bounded Context Bounded Context Bounded Context Bounded Context Rewards Domains Subdomains Bounded contexts Team ownership

Service Patterns Independent ly releasable single-purpose services

Service Patterns Domains Subdomains Bounded contexts Team ownership Microservices

Architecture Patterns

The world is asynchronous The world is event driven Dr. Werner Vogels CTO, Amazon.com AWS re:Invent 2022 The modern distributed applications’ Duo Asynchrony Event-Driven

The Duo – Asynchrony & Event-Driven Service A Service B Invokes with a request Returns with a response Service C Service D Submits a batch job Acknowledgment Job status Updates Polls Service C Service D Submits a batch job Acknowledgment Notification Service E Service F Messages Sends a message Receives a message

Event-driven architecture (EDA) is an architectural concept that uses events to communicate between decoupled applications asynchronously .

The elements of EDA Customer accounts Finance Customer service Event broker account created account created account created Event producer Event consumer Event broker or bus Events account deleted account deleted

Event producer or publisher Customer accounts Finance Customer service Event broker account created account created account created Agnostic of consumers Adds producer’s identity Conforms to a schema Unique event identifier Adds just the required data account deleted account deleted

Event consumer or subscriber Customer accounts Finance Customer service Event broker account created account created account created Idempotent Ordering not guaranteed Event authenticity Store events and process account deleted account deleted

Event broker, carrier, or bus Customer accounts Finance Customer service Event broker account created account created account created Support for multiple publishers & subscribers Routing events to many targets Event transformation Schema discovery and repository account deleted account deleted

An event is something already happened in the system.

Events – The data envelopes Customer accounts Finance Customer service Event broker account created account created account created Unique event identity Associate with a schema Immutable Carry just the required data account deleted account deleted

Event structure – Event detail {   " version ": "0",   " id ": "6a7e8feb-b491-4cf7",   " detail-type ": "order-submission",   " source ": “checkout",   " account ": "123456789012",   " time ": "2023-08-29T12:10:21Z",   " region ": "eu-central-1",   " resources ": ["arn:…your-event-bus"],    "detail" : { // Your data. A valid JSON   } {   "detail": {       "metadata": { // Details about the event        },        "data": { // The instance data        }   }

Event structure – Event metadata {   " version ": "0",   " id ": "6a7e8feb-b491-4cf7",   " detail-type ": "order-submission",   " source ": “checkout",   " account ": "123456789012",   " time ": "2023-08-29T12:10:21Z",   " region ": "eu-central-1",   " resources ": [" arn :…your-event-bus"],    "detail" : { // Your data. A valid JSON   } } {   "detail": {       "metadata": { “version”: ”1”, “ event_id ”: ”abcd-123-efg-456”, “domain”: “retail", “subdomain”: “checkout",          “service":  “orders",         “category":  “domain-event",         “type":  “data“, “name”: ” order_submitted ”       },        "data": {       }    } }

Event structure – Event data {   " version ": "0",   " id ": "6a7e8feb-b491-4cf7",   " detail-type ": "order-submission",   " source ": “checkout",   " account ": "123456789012",   " time ": "2023-08-29T12:10:21Z",   " region ": "eu-central-1",   " resources ": ["arn:…your-event-bus"],    "detail" : { // Your data. A valid JSON   } } {   "detail": {       "metadata": {       },        "data": { “order_number”: ”123-456x”, “total”: 29.99, “currency”: “USD",         “customer_id":  “cu-101",         “items": { }      } } }

Microservices choreography A coordinated performance of microservices

Service choreography is a coordinated sequence of actions across multiple microservices to accomplish a business process.

Use case: Product registration flow Product registration Award loyalty points Generate discount code Email discount code Inform customer support Notify manufacturer

Use case: Product registration flow Product registration Award loyalty points Generate discount code Email discount code Inform customer support Notify manufacturer There is dependency Not everything sequential Different systems involved Data format can differ External

Product registration choreography Products Loyalty Promotions Product registered App Product aftercare Customer Amazon EventBridge Product registered Product registered Product registered Product registered Discount generated Discount generated Amazon SES Third-party system Manufacturer Registration EventBridge rule API call API Destination

Service choreography – Key points Use choreography to coordinate between different microservices There is no controller ; each service performs its logic as per the event It promotes service decoupling and asynchrony, enabling extensibility Each service to implement idempotency measures to handle duplicate events Add traceability attributes in the events for better observability

Microservices orchestration An orchestrated performance of services

Image by https://pixabay.com/users/chenspec-7784448/ Orchestration is an automated and instructed coordination of several services and resources by an orchestrator to accomplish a business process.

Types of event-driven orchestration Distributed (asynchronous) orchestration In-service orchestration Cross-service orchestration

In-service orchestration Customers domain Registration microservice Accounts Consent Registration flow Start End Task A1 Task A2 Task A4 API Simplest form of orchestration inside a microservice’s boundary The microservice owns all the resources part of the orchestration Primary benefit is a self-contained microservice – except shared event bus to put events Most use cases suitable for express Step Functions Ideal for sync and async workflows

Customers domain Registration microservice Accounts Registration flow Start End Task A1 Task A2 Task A4 Event bus Cross-service orchestration Interaction with services inside and outside of the domain boundary Most interactions with other services is via synchronous API calls Use of express and standard Step Functions depending on the execution time Ideal for sync and async workflows Loyalty domain Members Rewards Orders Consent

Distributed orchestration Primary orchestrator Domain B Microservice B Start End Task B1 Task B2 Task B3 Task B4 Domain A Microservice A Start End Task A1 Task A3 Task A2 Task A4 Task A5 Task A6 Domain C Microservice C Start End Task C1 Task C3 Task C2 Couple of hours to complete Takes a week to finish

Coordinate distribution with EventBridge Domain B Microservice B Start End Task B 1 Task B2 Task B3 Task B4 Domain A Microservice A Start End Task A1 Task A3 Task A2 Task A4 Task A5 Task A6 Domain C Microservice C Start End Task C1 Task C3 Task C2

Events and task tokens Domain A Step Function A Start End Task A1 Task A3 Task A2 Task A4 Task A5 Task A6 Domain C Microservice C 1 2 3 4 5 1 Task A5 emits an event with a task token and waits 2 Microservice C reacts and performs its job 3 Microservice C emits an event with the task token 4 A function submits the token to the Step Function 5 Step Function A resumes from Task 5 Amazon EventBridge

Distributed orchestration – Key points You can use m ultiple task tokens in a Step Function workflow; each token is unique Task token transport can be via EventBridge, SQS, SNS, and more Set a timeout for the task; extend the heartbeat interval when a task takes longer If one task token submission reports failure, the state machine itself fails Remote services to store the correlation of task request with the respective token

Building better orchestrations – Blog https://bit.ly/38Yxmwd

Sustainable Development

Traditional way of thinking Serverless way of thinking Requirements Analysis Design Development Testing Release Maintenance Ideate Design Build Operate Sustain MVP – Minimum Viable Product MVP – Most Valuable Product Sustain Maintain

The ability to keep something going for a prolonged period by nurturing it with a continuous provision of nourishment to ensure its growth and existence .

Sustain ability triangle Process Product Sustainability in Serverless Cloud Building sustainable serverless solutions Following sustainable development processes Applying cloud best practices Sustainability of the cloud Sustainability in the cloud Long-lived Max long-term value Principles Practices Operating platform

Modular Extendable Observable Characteristics Domains, boundaries, contracts Independent smaller microservices Structured logs and distributed traces Measurable metrics Asynchronous and loosely coupled Event-driven architecture Sustainable product

Sustainable processes Follow Lean Principles Reduce Waste Improve Value Stream Agile & Pragmatic Start Small & Scale Evolve in Iterations Automate Everything DevOps Mindset Refactor Continuously Grow Serverless Teams Educate Engineers Instil Ownership

Sustainable cloud Renewable energy Efficient power & cooling Sustainability of the Cloud Development language Data stores & policies Sustainability in the Cloud Server population Right sizing resources Shared resources On-demand scaling Compute & storage tiers options Managed services Customer Cloud

Development Practices

Perform Solution Design Technical agility Engineering clarity Business visibility Service longevity https://bit.ly/3tPEe7D

Security & Threat Modelling Security from the start Data privacy GDPR & C ompliance Service protection https://qrgo.page.link/aiQsb

# Automation & DevOps Account separation Infrastructure as Code ( IaC ) Grow CI/CD pipeline Instil a DevOps culture Integration tests Test in real environment Alerts and alarms Service ownership

Cloud Account Separation Production QA Develop Checkout Services Production QA Develop Payment Services

Cloud Account Separation Production QA Develop Checkout Services Production QA Develop Payment Services Sandbox

Set Pieces in Practice

Backend service Rewards CMS 3 rd Party CRM Website Stores details Business stakeholder Customer Uploads rewards content Redeems rewards Fetches rewards content Updates rewards data Requests redemption Use case : A rewards system

Backend service Rewards CMS 3 rd Party CRM Website Stores details Business stakeholder Customer Uploads rewards content Redeems rewards Fetches rewards content Updates rewards data Requests redemption Domain : Ecommerce Subdomain : Customer Bounded Context : Rewards Use case : A rewards system

Rewards One monolith service One delivery pipeline One observable complex view One bounded context One macro service Rewards commit build test stage production Rewards bounded context A traditional rewards system

How to handle one part with a high degree of change ? Why deploy everything every time ? How to have high visibility of the critical parts ? Would ACL be part of the same service? What will be the developer experience ?

Backend service Rewards CMS 3 rd Party CRM Website Stores details Business stakeholder Customer Uploads rewards content Redeems rewards Fetches rewards content Updates rewards data Requests redemption Find the core service(s) Rewards service Mark the data pipelines Reward data upload Anti-corruption layers CMS & Rewards (ACL) Rewards & CRM (ACL) Rewards system pieces Fraud detection Communications Data audit

Content upload CMS ACL Rewards CRM ACL Rewards System Bounded Context CMS CRM Website But how do they communicate? Rewards system microservices

Dialogue Music Events APIs Content Updates Rewards Communication Contract Messages Connecting the pieces

Content upload CMS ACL Rewards CRM ACL Rewards System Bounded Context CMS CRM Website Sync API Async webhook Sync API Async events Async events Connecting the pieces

Many single-purpose microservices Independent release pipelines Granular operational view One bounded context multiple microservices Rewards bounded context Content upload CMS ACL Rewards CRM ACL Rewards CRM ACL Independently releasable microservices Set piece services

Content upload CMS ACL Rewards Rewards System Bounded Context CRM ACL Production QA Develop Sandbox Stream-aligned team Bounded context & microservices Operated by one team Event Sourcing Admin Reports Emails Making the whole / Completing the vision

Public API clients Loyalty Bounded Context SaaS CRM Data Gateway Loyalty Core Event Bus Audit Service Order Processor Auth Service Admin Rewards Manager Members SaaS Survey Data Lake NPS Feeder CRM Mediator Fraud Engine Webhooks Other domain 3 rd Party

Serverless Characteristics Industry Patterns Service Boundaries Think Sustainability Asynchrony Event-Driven Team Autonomy Vision & Focus Monitor & Observability Evolve Architecture

Technologist O’Reilly Author AWS Serverless Hero Sheen Brisals sheen- brisals sheenbrisals sbrisals.medium.com Thank You! #TheServerlessBook tinyurl.com/2ncnx2u4