Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service...

35
Microservices Lessons Learned From a Startup Perspective Susanne Kaiser @suksr CTO at Just Software @JustSocialApps

Transcript of Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service...

Page 1: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Microservices Lessons Learned From a

Startup Perspective

Susanne Kaiser@suksr

CTO at Just Software@JustSocialApps

Page 2: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Each journey is different

“People try to copy Netflix, but they can only copy what they see. They copy the results, not the process.”

Adrian Cockcroft, AWS VP Cloud Archtitect, former Netflix Chief Cloud Architect

Page 3: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Affecting Circumstances

Team● Size● Skillset● Structure

Legacy-System● Maintenance effort ● Environment

Strategy● New Features● Timeline/Milestones

Page 4: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Background

JUST PAGESocial Network

JUST CONNECTReal-time collaboration

JUST DRIVEDocument Sharing

JUST TASKSTask Management

JUST PEOPLEUser Management

Page 5: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Background

One team

One collaboration product

One technologystack

Single Unit

At The Beginning … A Monolith In Every Aspect

Page 6: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Productivity suffered

Usability and UX suffered

New features released slowly

Background

After An Evolving Time ...

Page 7: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Background

JUST PAGESocial Network

JUST CONNECTReal-time collaboration

JUST DRIVEDocument Sharing

JUST TASKSTask Management

JUST PEOPLEUser Management

Separate Collaboration Apps

Page 8: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Background

JUST PAGESocial Network

JUST CONNECTReal-time collaboration

JUST DRIVEDocument Sharing

JUST TASKSTask Management

Small, Autonomous Teams

JUST PEOPLEUser Management

With well-defined responsibilities

Page 9: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Background

Product Organization Software architecture

In The Long Run ...

Page 10: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Straightforward Process?

Start End

Page 11: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

No Straightforward Process!

Start

Theory Reality

Start End

Page 12: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

First Approach As Co-Existing Service

JUST DRIVE

JUST DRIVE

JUST LIST

JUST CONNECT

JUST PAGE

DB Adapter

REST API

Web App

DB Adapter

MessageBroker

Messa

ge Br

oker

Adap

ter

Message Broker

Adapter

Page 13: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Lesson #1: Too Many Steps At Once Slow You Down

More features

New UI

New data structure

Maintain & runcurrent system

Timelines

Page 14: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Start With One Manageable Step At A Time

Easy to extract Changing frequently

Different resource requirements Split in steps, e.g.

top/down

Page 15: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Lesson #2: Deferring Solving Authz Handling Hurts

I have a new service that needs authorization. Where isthe authz service I could use?

Not there, yet. Sorry!

Ok, than I am putting my codeto the place where authz handling exists … to the monolith.

Feeding the monolith

I have a new service that needs authorization. Where isthe authz service I could use?

Not there, yet. Sorry!

Ok, than I am implementing authzin my local service.

Re-implementing authz w/ every service

Page 16: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Lesson #2: Deferring Solving Authz Handling Hurts

Solve Authz Handling Early!

Page 17: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Lesson #3: Less Aligned Strategy Is Expensive

Separate Apps Separate Teams Separate Services Bundled Deployment

Page 18: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Lesson #4: Data Related Overhead

Setup Maintain SetupSetup Maintain

Keep in sync

Page 19: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Lesson #4: Data Related Overhead

Streams

Page 20: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

How To Interact Between Services?

Request-Driven Event-Driven

command

query

produceconsume

Event-Stream

Hybrid

produceconsume

command/query

Event-Stream

Page 21: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

How To Manage Data?

ProfileService

DocumentService

TaskService

Hybrid Model

REST

getProfile(ProfileId)Remote query directly to source

Event stream purely for notifications

Page 22: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

How To Manage Data?

ProfileService

DocumentService

TaskService

Event-Driven State Transfer

ProfileUpdatedEvent

Local copy/cache

Page 23: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

How To Manage Data?Source Of Truth

Database

Events

“Traditional” Event-Driven System

Page 24: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

How To Manage Data?Multiple Sources Of Truth

Database

Events

Internal source of truth

External source of truth

Dual writes

“Traditional” Event-Driven System

Page 25: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

How To Manage Data?Multiple Sources Of Truth

Database

Events

Internal source of truth

External source of truth

Dual writes

“Traditional” Event-Driven System Event Sourcing

Derive state from events

Event-Store

Single Source Of Truth

Events as first-class entities

Page 26: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Apache Kafka

P0 P1 P2 P30123

012

0123

0123

Consumer

Topic

Consumer Consumer Consumer Consumer

Consumer Group Consumer Group

Producer

Each partition is assigned to one consumer within

a consumer group

Immutable, ordered sequence of records per partition

Each consumer controlsits position per partition(offset)

writes

readsEach consumer subscribes

to a topic

Consumer

Page 27: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Apache Kafka

P0 P1 P2 P30123

012

0123

0123

Consumer

Topic

Consumer Consumer Consumer Consumer

Consumer Group Consumer Group

Producerwrites

reads

Scalable

Fault-tolerant

Node/Broker

● Data stored to disk● Replicated partitions● Consumer conrols its offset

● Topic can be scaled outto several nodes

● Messages load-balancedbetween consumer of one group

● Add partitions for more parallelism● Adding capacity with 0 downtime

Fast ● O(1) to append messages● LinkedIn 2016:

1.4 trillion messages/day across over 1400 brokers

Consumer

Page 28: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Apache Kafka Combines ...

Messaging System Storage System Streaming Platform

Page 29: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Primary Use Cases Of Streaming Platforms

Stream Processing Data Integration

Source

Sink

Page 30: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Kafka Streams

Topic

Unbounded, ordered sequence

Key/value-pairContinuouslyupdating

Page 31: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Kafka Streams

Topic Service

State Store (disk backed)

Running in the process of Microservice

Loads topic on startup

Streams can be:● Joined● Filtered● Grouped● Aggregated ● etc.Streams make data available wherever it’s needed

Page 32: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Kafka Streams For Materialized Views

Document Topic

Profile Topic

Document Service

API

Table for enrichment

Stream

Matererialized View as State Store

Stream-Table-Join

Page 33: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

Low Barrier To Entry For New Service

● No separate data storage to set up● No extra local copies / caches to set up and to keep in sync● No remote calls● Materialized View always up to date● Scalable, fault-tolerant, fast

=> reducing overhead, increasing performance & autonomy

Page 34: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

If We Could Start The Journey Again ...

● Start with one manageable step at a time● Take care of Authorization handling early● Align strategy w/ Microservices goals● Using Kafka Streams for Materialized Views

Page 35: Microservices Lessons Learned From a Startup Perspective · updating. Kafka Streams Topic Service State Store (disk backed) ... Joined Filtered Grouped Aggregated etc. Streams make

THANK YOU!Susanne Kaiser

@suksr

CTO at Just Software@JustSocialApps