Microservices Lessons Learned Susanne Kaiser Independent Tech - - PowerPoint PPT Presentation

microservices lessons learned
SMART_READER_LITE
LIVE PREVIEW

Microservices Lessons Learned Susanne Kaiser Independent Tech - - PowerPoint PPT Presentation

Microservices Lessons Learned Susanne Kaiser Independent Tech Consultant @suksr @suksr Software Delivery Performance Profitability, Productivity & Market Share @suksr @suksr @suksr Challenges Of Microservices @suksr Background


slide-1
SLIDE 1

Microservices Lessons Learned

Susanne Kaiser Independent Tech Consultant @suksr

@suksr

slide-2
SLIDE 2

Software Delivery Performance

Profitability, Productivity & Market Share

@suksr

slide-3
SLIDE 3

@suksr

slide-4
SLIDE 4

@suksr

slide-5
SLIDE 5

Challenges Of Microservices

@suksr

slide-6
SLIDE 6

Background

@suksr

CTO at Just Software @JustSocialApps

Susanne Kaiser … who?

Independent Tech Consultant @suksr Co-Organizer @microXchg, Berlin Program committee ServerlessDays, Hamburg @ServerlessHAM Program committee MicroCPH, Copenhagen @MicroCPH Program committee & track host QCon, New York @qconnewyork

slide-7
SLIDE 7

Background

Motivation for Microservices

Autonomous teams Develop independently Deploy independently Work at different parts independently Scale independently At different speed @suksr

slide-8
SLIDE 8

Challenges Of Microservices

Organizational Circumstances

@suksr

slide-9
SLIDE 9

Organizational Circumstances

Team

Structure Skillset Size

Journey

@suksr

slide-10
SLIDE 10

Team

Structure Skillset Size

Journey Legacy

Maintenance effort Runtime environment @suksr

Organizational Circumstances

slide-11
SLIDE 11

Team

Structure Skillset Size

Journey Legacy

Maintenance effort Runtime environment

Strategy

New Features Timeline / Milestones @suksr

Organizational Circumstances

slide-12
SLIDE 12

Challenges Of Microservices

Organizational Manageable Steps Circumstances

@suksr

slide-13
SLIDE 13

Identify Bounded Contexts

High cohesion within a service Loose coupling between services @suksr

slide-14
SLIDE 14

High cohesion within a service Loose coupling between services Bounded Context Related behaviour Semantic boundary around domain model Well-defined business function @suksr

Identify Bounded Contexts

slide-15
SLIDE 15

JUST DRIVE JUST CONNECT JUST LIST JUST WIKI JUST PEOPLE JUST NEWS

Bounded Contexts

@suksr

Examples for Bounded Contexts

slide-16
SLIDE 16

JUST DRIVE

Decomposition Strategy

Co-Existing Service From Scratch

@suksr

slide-17
SLIDE 17

JUST DRIVE

Decomposition Strategy

Co-Existing Service From Scratch

JUST PEOPLE @suksr

slide-18
SLIDE 18

Decomposition Strategy

Co-Existing Service From Scratch

  • wns document

state

REST API Application-Service Domain-Model DB Adapter Monolith

JUST DRIVE @suksr

slide-19
SLIDE 19

Decomposition Strategy

Co-Existing Service From Scratch

  • wns document

state

  • wns profile

state document created by author

Monolith REST API Application-Service Domain-Model DB Adapter

@suksr

slide-20
SLIDE 20
  • wns document

state

  • wns profile

state

Events

local copy

  • f author

Message Broker

Decomposition Strategy

Co-Existing Service From Scratch

REST API Application-Service Domain-Model DB Adapter Message Broker Adapter Monolith publish subscribe

@suksr

slide-21
SLIDE 21

DB Adapter Message Broker Adapter Application-Service Domain-Model REST API Domain-Event

Good approach in general, but we did too many steps at once

New UI New Business Logic New Data Structure

=> Not optimal to start with

vs.

Decomposition Strategy

Co-Existing Service From Scratch

@suksr

slide-22
SLIDE 22

Start Small

Easy to Extract

@suksr

slide-23
SLIDE 23

Incremental Decomposition Top-Down

  • or -

Monolith Monolith Monolith

Incremental Decomposition Bottom-Up

  • Monolith

Monolith Monolith

Decompose in Steps

@suksr

slide-24
SLIDE 24

Challenges Of Microservices

Organizational Manageable Steps Cross-Cutting Concerns Circumstances

@suksr

slide-25
SLIDE 25

Cross-Cutting Concerns

Authorization

JUST DRIVE JUST WIKI Fine-grained authorization Inter-service dependency @suksr

slide-26
SLIDE 26

Cross-Cutting Concerns

I have a new service that needs authorization. Where is the authz service I could use? Not there, yet. Sorry! Ok, then I am putting my code to the place where authz handling exists … to the monolith.

Feeding the monolith Re-implementing authz w/ every new service

Ok, then I am implementing authz in my local service.

Authorization

@suksr

slide-27
SLIDE 27

Cross-Cutting Concerns

Handle Them Early

Feeding the monolith Re-implementing authz w/ every new service

Handle Cross-Cutting Concerns Early

@suksr

slide-28
SLIDE 28

Challenges Of Microservices

Organizational Manageable Steps Cross-Cutting Concerns Distributed Monolith Circumstances

@suksr

slide-29
SLIDE 29

Cross-Cutting Concerns

Avoid A Distributed Monolith

Authz Service @suksr

Does a change to one microservice require changes to

  • r deployments of other microservices?
slide-30
SLIDE 30

Cross-Cutting Concerns

Avoid A Distributed Monolith

Authz Service

conform

One stable common contract

conform conform

@suksr

slide-31
SLIDE 31

Challenges Of Microservices

Organizational Manageable Steps Cross-Cutting Concerns Distributed Monolith Circumstances Service-Interaction, Shared Data & Event-Patterns

@suksr

slide-32
SLIDE 32

Service Interaction

Request-Driven / Event-Driven

command query Events Message Broker publish subscribe command query

Request-Driven Hybrid

Events Message Broker publish subscribe

Event-Driven

@suksr

slide-33
SLIDE 33

How To Manage Shared Data?

Hybrid Model

Message Broker

REST API

Remote query directly to source Events for notification @suksr

slide-34
SLIDE 34

Event Driven State Transfer

Message Broker

Local copy of profile data ProfileUpdatedEvent

How To Manage Shared Data?

Events for data duplication @suksr

slide-35
SLIDE 35

Source Of Truth

How To Manage Shared Data?

Internal source of truth External source of truth

Multiple sources of truth Single source of truth

Events as first-class citizens

“Traditional” Event-Driven System Event Log

@suksr Dual Writes Risk of Inconsistencies Events as primary data source

slide-36
SLIDE 36

Event Log

Profile Created Page Created Doc Uploaded Page Archived Profile Deactivated

Event = A fact that has happened in the past Immutable Append-Only Persisted Ordered Sequence of Events

@suksr

slide-37
SLIDE 37

Event Sourcing

State changes modeled as series of events

Profile Created Profile Updated Profile Deactivated

Events are persisted & appended to the event log Current state is reconstructed by replaying events

Profile State

Services can subscribe to the event log

Subscriber @suksr

slide-38
SLIDE 38

Firstname Lastname Update Your Profile

Client Event Log

Event Sourcing

@suksr

slide-39
SLIDE 39

Firstname Lastname Update Your Profile

How to derive materialized views?

Client Event Log

Event Sourcing

@suksr

slide-40
SLIDE 40

Event-Sourcing

Firstname Lastname Update Your Profile

Materialized Views

EventHandler Query Read Store

@suksr

slide-41
SLIDE 41

Event-Sourcing

Firstname Lastname Update Your Profile

Materialized Views

EventHandler Query

How to update state?

Read Store

@suksr

slide-42
SLIDE 42

Firstname Lastname Update Your Profile

State Changes w/ Commands & Events

EventHandler Query Command Event Read Store

Event-Sourcing

@suksr

slide-43
SLIDE 43

Firstname Lastname Update Your Profile

State Changes w/ Commands & Events

EventHandler Query Command Event Read Store

Event-Sourcing

@suksr Read events of profile replay events to build internal state check invariants

  • n internal state

save event generate event & update internal state

slide-44
SLIDE 44

Event-Sourcing

Firstname Lastname Update Your Profile

CQRS

EventHandler Query Command Event Seperate Models Change state (write model) Request data (read model) Read Store

@suksr

slide-45
SLIDE 45

Event-Sourcing

Firstname Lastname Update Your Profile

CQRS

EventHandler Query Command Event Seperate Models Change state (write model) Request data (read model) Can be scaled independently Can be deployed separately Read model can be optimized to make queries fast & efficient

Commands & Queries

Read Store Might involve more work due to transforming events to a read model Might have a higher learning curve

@suksr

slide-46
SLIDE 46

Event-Sourcing

Username Password Register Registration

EventHandler Query Command Event Read Store

How to preserve business constraints among domain models, e.g. unique usernames? Validation

@suksr

slide-47
SLIDE 47

Event-Sourcing

Username Password Register Registration

EventHandler Query Command Event

How to preserve business constraints among domain models, e.g. unique usernames?

Username Query Read Store Allocated Usernames

Validation

@suksr

slide-48
SLIDE 48

Username Password Register Registration

EventHandler Query Command Event

How to preserve business constraints among domain models, e.g. unique usernames?

Username Query Read Store Allocated Usernames

Validation: New Read Store & Client-side Query Execution

Eventual Consistency Malicious Client?

Event-Sourcing

@suksr

slide-49
SLIDE 49

Username Password Register Registration

EventHandler Query Command Event

How to preserve business constraints among domain models, e.g. unique usernames?

Username Query

Read Store Allocated Usernames

Validation: New Read Store & Client-side Query Execution

Eventual Consistency Malicious Client? Accounts w/ duplicated usernames

Event-Sourcing

@suksr

slide-50
SLIDE 50

Username Password Register Registration

EventHandler Query Command Event

How to preserve business constraints among domain models, e.g. unique usernames?

Username Query

Read Store Allocated Usernames

Validation: New Read Store & Client-side Query Execution + Saga Pattern

Eventual Consistency Malicious Client? Accounts w/ duplicated usernames Compensating Event

corrected by

Saga Pattern

Event-Sourcing

@suksr

slide-51
SLIDE 51

Events for notification Event Driven State Transfer

  • Simple integration
  • No local datasets to maintain
  • Remote query => increasing coupling
  • Eliminating remote query by

introducing local copy => better decoupling

  • Local copy => better autonomy
  • Duplicating effort to maintain

local dataset Event Sourcing w/ CQRS

  • Series of events make activities in business

domain explicit

  • Complete log of state changes => eases

troubleshooting

  • Independant scaling of read & writes
  • Read store can be optimized to queries
  • Enables audit logging
  • Might involve more work due to

transforming events to a read model

  • Preserving business contraints among

domain objects could be tricky @suksr

Event-Patterns

Message Broker Message Broker Event Log

Query Command Query Command

slide-52
SLIDE 52

Challenges Of Microservices

Organizational Manageable Steps Cross-Cutting Concerns Distributed Monolith Service-Interaction, Shared Data & Event-Patterns Circumstances Infrastructure & Operational Complexities

@suksr

slide-53
SLIDE 53

µService

@suksr

Complexities

slide-54
SLIDE 54

Hardware Data Store API API-Gateway Service Discovery Load-Balancer Message Broker Timeout-Handling Retries Idempotency Bulkheads Circuit Breaker Config-Mngmt. Monitoring Log Aggreation Metrics Distributed Tracing Health Checks SCM O/S Virtualization Container Runtime

Checkout Test Build

CI/CD Pipeline

Deploy

µService Backup Recovery

@suksr

Complexities

slide-55
SLIDE 55

Hardware Data Store API API-Gateway

Service Discovery Load-Balancer

Message Broker Timeout-Handling Retries Idempotency Bulkheads Circuit Breaker Config-Mngmt. Monitoring Log Aggreation Metrics Distributed Tracing Health Checks

SCM

O/S Virtualization Container Runtime Checkout Test Build

CI/CD Pipeline

Deploy Backup Recovery

@suksr

Complexities

slide-56
SLIDE 56

Hardware Data Store API API-Gateway Service Discovery Load-Balancer Message Broker Timeout-Handling Retries Idempotency Bulkheads Circuit Breaker Configuration Monitoring Log Aggreation Metrics Distributed Tracing Health Checks SCM O/S Virtualization Container Runtime

Checkout Test Build

CI/CD Pipeline

Deploy

µService

Team

Structure Skillset Size

Strategy

New Features Timeline / Milestones

Legacy

Maintenance effort Runtime environment Backup Recovery

@suksr

Complexities

slide-57
SLIDE 57

@suksr

Complexities

slide-58
SLIDE 58

How can a small team handle infrastructure complexities and deliver business value?

@suksr

Complexities

slide-59
SLIDE 59

Build the things that differentiate you Offload the things that don’t

@suksr

slide-60
SLIDE 60

Hardware O/S Virtualization Container Runtime

Managed Services

O/S Orchestration Data Store µService

Offload by getting common building blocks managed

@suksr

slide-61
SLIDE 61

Cloud Native

Managed by YOU Managed by Platform Hardware O/S Virtualization Container Runtime O/S Orchestration µService Container Runtime µService Service Discovery Load Balancer Config-Mngmt. Monitoring Log Aggreation Health Checks Recovery Scaling

w/ Container Orchestration

Message Broker Data Store Backup API-Gateway

@suksr

slide-62
SLIDE 62

Separation Of Concerns

Service Discovery Load-Balancer Circuit Breaker Timeout Retries Bulkheads Kubernetes / Service Mesh Proxy Proxy

Business Logic Service Mesh Application Networking Concerns

@suksr

slide-63
SLIDE 63

Hardware O/S Virtualization Container Runtime O/S Orchestration Data Store µService Hardware O/S Virtualization Container Runtime O/S Orchestration Data Store Function Managed by YOU Managed by Third Party Unit of Work

@suksr

Serverless

slide-64
SLIDE 64

Serverless

Function Event

Event-Driven Workflow

Hardware Data Store O/S Virtualization Container Runtime

Fully Managed By Third Party Ephemeral Function Pay-per-Execution Auto-Scaling Characteristics

@suksr

triggers

slide-65
SLIDE 65

Serverless

Example Backend API

listProfile

One function per endpoint and action

API

getProfile createProfile updateProfile deleteProfile

API-Gateway

GET /profiles GET /profiles/{id} POST /profiles PUT /profiles/{id} DELETE /profiles/{id} ProfilesService @suksr

slide-66
SLIDE 66

Serverless

Benefits

Low Maintenance Low Cost (Total Cost of Ownership) Easy to Scale Focus on Code => Focus on Core Domain

@suksr

slide-67
SLIDE 67

Serverless

Constraints

  • Limitation in programming languages and runtimes
  • Latency at initial requests (cold start)
  • Limits of RAM, deployment package size, number of parallel executions
  • (Maximum Execution Time)
  • Tooling for distributed tracing
  • Vendor Lock-In

@suksr

slide-68
SLIDE 68

Start small

Lessons Learned

Handle cross-cutting concerns early Avoid a distributed monolith Be aware of affecting circumstances & Distributed Systems are Complex :) Design event-driven to be easy to evolve @suksr Consider managed services to offload infrastructure complexities

slide-69
SLIDE 69

Susanne Kaiser Independent Tech Consultant @suksr