data architecture not just for microservices

85
Data Architecture – Not Just for Microservices Eberhard Wolff @ewolff Fellow

Upload: eberhard-wolff

Post on 06-Jan-2017

297 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Data Architecture not Just for Microservices

Data Architecture –Not Just for

MicroservicesEberhard Wolff

@ewolffFellow

Page 2: Data Architecture not Just for Microservices

http://continuous-delivery-buch.de/

Page 3: Data Architecture not Just for Microservices

http://microservices-buch.de/ http://microservices-book.com/

Page 4: Data Architecture not Just for Microservices

http://microservices-book.com/primer.html

FREE!!!!

Page 5: Data Architecture not Just for Microservices
Page 6: Data Architecture not Just for Microservices

Classic Data Architecture

> Centralized databases

> …or services that provide data

> Ensures consistency across systems

> …for data model

> ...and updates to data

> Reuse

Page 7: Data Architecture not Just for Microservices

Classic Data Architecture

Billing OrderProcess CRM

Order

Page 8: Data Architecture not Just for Microservices

Who is using a centralized database?

Page 9: Data Architecture not Just for Microservices

Who likes thecentralized database?

Page 10: Data Architecture not Just for Microservices

Microservices: Definition

> No consistent definition

> Microservices are modules

> Independent deployment units

> E.g. processes, Docker container

> Microservice owned by one team

Page 11: Data Architecture not Just for Microservices

Microservices: Definition

Server /Container

Server / Container

MicroService

MicroService

Page 12: Data Architecture not Just for Microservices

Why Microservices?> Develop a feature

> …bring it into production

> ...with no coordination

> Independent scaling

> Free choice of technology

> Robustness

> Security

Page 13: Data Architecture not Just for Microservices

Microservices aim for decoupling

Page 14: Data Architecture not Just for Microservices

Microservices & Data

Server /Container

Server / Container

MicroService

MicroService

Order Schema

Page 15: Data Architecture not Just for Microservices

Microservices & Data

Server /Container

Server / Container

MicroService

MicroService

Order Schema

Page 16: Data Architecture not Just for Microservices

Microservices & Data

> Decoupling for data, too

> Separate data storage

Page 17: Data Architecture not Just for Microservices

Data Microservices

Server /Container

Server / Container

MicroService

MicroService

Order DataMicroservice

Page 18: Data Architecture not Just for Microservices

Data Microservices

Server /Container

MicroService

Order DataMicroservice

Customer DataMicroservice

Remote callsinfluence

performanceavailability

No transactionacross customer

and order

Page 19: Data Architecture not Just for Microservices

Data Microservice> Change two microservices if new feature

requires change to data schema

> Transactions?

> But: data in one place

> No consistency issues

Page 20: Data Architecture not Just for Microservices

Data microservice limits decoupling.

Page 21: Data Architecture not Just for Microservices

Encapsulation

> Information hiding

> Hide the internal data structure

> Provide access only through a well defined interface

> Data and databases should not be exported

Page 22: Data Architecture not Just for Microservices

Violates Encapsulation

Billing OrderProcess CRM

OrderShared

data model

Logic

Page 23: Data Architecture not Just for Microservices

Violates Encapsulation

Server /Container

Server / Container

MicroService

MicroService

Order DataMicroservice Shared

data model

Logic

Page 24: Data Architecture not Just for Microservices

Why You Should Avoid a Canonical Data

Model (Stefan Tilkov)

https://www.innoq.com/de/blog/thoughts-on-a-canonical-data-model/

Page 25: Data Architecture not Just for Microservices

Separate Databases

Server /Container

Server / Container

MicroService

MicroService

Order Order

Page 26: Data Architecture not Just for Microservices

Different Databases

Server /Container

Server / Container

MicroService

MicroService

neo4j Oracle

Page 27: Data Architecture not Just for Microservices

Different Databases> “Polyglot persistence”

> Use the best tool for the job

> Technology freedom– advantage of microservices

> …but extra effort

> Backup, disaster recovery etc.

> Not as easy as e.g. different frameworks

Page 28: Data Architecture not Just for Microservices

Separate Schema

Server /Container

Server / Container

MicroService

MicroService

OracleSchema Schema

Page 29: Data Architecture not Just for Microservices

Separate Schemas

> Less effort

> Decoupled data models

> ...but limited independent scaling and robustness

Page 30: Data Architecture not Just for Microservices

Billing OrderProcess CRM

OrderOrder Order

Page 31: Data Architecture not Just for Microservices

Redundancy!!!

Page 32: Data Architecture not Just for Microservices
Page 33: Data Architecture not Just for Microservices
Page 34: Data Architecture not Just for Microservices

Domain-driven Design

Page 35: Data Architecture not Just for Microservices

Domain-driven Design

> 2004

> Still very relevant

> By Eric Evans

> Focus on part IV

> Free reference: http://domainlanguage.com/ddd/reference/

Page 36: Data Architecture not Just for Microservices

Order

Shipping addressTracking #ItemsItem CategoriesPriority shippingCustoms #Account #

...Credit card #

Order #

Page 37: Data Architecture not Just for Microservices

My Domain Modelis a mess!

Page 38: Data Architecture not Just for Microservices

Bounded Context

> Domain model is only valid for one context

> There is no universal data model!

> See all failed SOA attempts

Page 39: Data Architecture not Just for Microservices

Order

Shipping addressTracking #ItemsItem CategoriesPriority shippingCustoms #Account #

...Credit card #

Order #

Customs

Order

Recommen-dations

Order

Tracking

Order

ShippingaddressTracking #

ItemCategories

Priorityshipping

Customs #

Payment

Order

Account #Credit card #

Page 40: Data Architecture not Just for Microservices

Billing OrderProcess CRM

OrderOrder Order

Page 41: Data Architecture not Just for Microservices

Bounded Context

> Microservice =BOUNDED CONTEXTS

> Changes for new features are local

> …even if data models need to be changed

Page 42: Data Architecture not Just for Microservices

Billing OrderProcess CRM

OrderOrder Order

Page 43: Data Architecture not Just for Microservices

Redundancy?

Page 44: Data Architecture not Just for Microservices

Redundancy?Not really

Page 45: Data Architecture not Just for Microservices

Bounded Context

Page 46: Data Architecture not Just for Microservices

What aboutbasic data of an

order?

Page 47: Data Architecture not Just for Microservices

Strategic Design

> How do BOUNDED CONTEXTS relate to each other?

> Context can have relationships

> DDD defines several relationship patterns

Page 48: Data Architecture not Just for Microservices

Shared Kernel

> Subset of a model

> …that two teams share

> Eric Evans: Including code and database

> Microservices: Just sharing a model

Page 49: Data Architecture not Just for Microservices

Anti-corruption Layer

> Don’t let e.g. a legacy model influence a new model

> Isolate model by additional layer

> No need to modify the old system

Page 50: Data Architecture not Just for Microservices

Context Relationships

> Team = Deployment Unit = BOUNDED CONTEXT

> Context Relationships define how BOUNDEDCONTEXT are used…

> ...and how much teams need to collaborate

Page 51: Data Architecture not Just for Microservices

CoordinationEffort

Shared BOUNDED CONTEXT

SHARED KERNEL

CUSTOMER / SUPPLIER

ANTICORRUPTION LAYER

CONFORMIST

SEPARATE WAYS

Page 52: Data Architecture not Just for Microservices

Context Map

Page 53: Data Architecture not Just for Microservices

Context Map

> Show the different BOUNDED CONTEXT

> …and the relation to each other

> BOUNDED CONTEXT might be microservices

> ...or communication links

Page 54: Data Architecture not Just for Microservices

Order ProcessRegistration

BasicCustomer

DataBasic

Customer Data

Customer OrderData

DeliveryCustomer

OrderData

Billing

AnticorruptionLayer

MainframeCustomer

Data

Customer OrderData

Customer OrderData

Basic CustomerData +

Customer Order Data

= Shared Kernel

Page 55: Data Architecture not Just for Microservices

Billing OrderProcess

CRM

SharedKernelOrder

Additionaldata

Additionaldata

Additionaldata

OrderData

Page 56: Data Architecture not Just for Microservices

CentralizedShared Kernel

> Ensures consistency

> ...but needs to be called for a lot of operations

> Resilience / performance / transactions

> Have one master as the source of truth

Page 57: Data Architecture not Just for Microservices

Billing OrderProcess

CRM

SharedKernelOrder

SharedKernelOrder

SharedKernelOrder

Additionaldata

Additionaldata

Additionaldata

Page 58: Data Architecture not Just for Microservices

DecentralizedShared Kernel

> Might be inconsistent

> ...but all data for all requests is available in the local database

> Better resilience…

> ...and performance

Page 59: Data Architecture not Just for Microservices

How to Replicate Data?

Page 60: Data Architecture not Just for Microservices

Database Replication

> Built into the database

> Replicate schema across database instances

> But: Microservices have separated schemas

> Every Microservice might have different data

> …so database replication is not a good fit

Page 61: Data Architecture not Just for Microservices

Replication with Events

Page 62: Data Architecture not Just for Microservices

Events

> Later addition to Domain-driven Design

> Events with a business meaning

> Decouple time:Asynchronous

> Decouple logic:System can handle event as it pleases

Page 63: Data Architecture not Just for Microservices

Billing OrderProcess

CRM

SharedKernelOrder

SharedKernelOrder

SharedKernelOrder

Additionaldata

Additionaldata

Additionaldata

New Order Event

Page 64: Data Architecture not Just for Microservices

Events & Data Replication

> Events lead to data replication

> i.e. each system stores information it received in an event

> Data stored in separate schema

> Very decoupled

> Hard to repair inconsistencies

Page 65: Data Architecture not Just for Microservices

More Fun With Events

Page 66: Data Architecture not Just for Microservices

Event Sourcing

> Internal Structure for Microservice with events

> Current state result of all events

> Calculate state on the fly?

Page 67: Data Architecture not Just for Microservices

Event Queue

Event

Event

Event

EventHandler

EventHandler

EventStore

Snapshot

Page 68: Data Architecture not Just for Microservices

Event Sourcing

> Event store and snapshot help to repair inconsistencies

> Event-based architecture in microservices

Page 69: Data Architecture not Just for Microservices

CQRS

> Command – Query Responsibility Segregation

> Commands change data

> Query provide data

> Implement in separate modules

> …or even microservices

> ...with potentially different BOUNDED CONTEXTS

Page 70: Data Architecture not Just for Microservices

Commands vs Events

> Command: Change that data!

> Event: Something has happened

> Component decides if data should be changed

Page 71: Data Architecture not Just for Microservices

CommandQueue

Command

Command

Command

CommandHandler

QueryHandler

CommandStore

Database

Page 72: Data Architecture not Just for Microservices

Batch Replication

Page 73: Data Architecture not Just for Microservices

Batch

> Get all data

> Provide API

> …to decouple schema

> Copy interesting data into local database

Page 74: Data Architecture not Just for Microservices

Billing OrderProcess

CRM

SharedKernelOrder

SharedKernelOrder

SharedKernelOrder

Additionaldata

Additionaldata

Additionaldata

BatchBatch API API

Page 75: Data Architecture not Just for Microservices

Batch & Data Replication

> Easy to repair inconsistencies

> Batch run at specific points

> i.e. updates take time

> Data not consistent across microservices

Page 76: Data Architecture not Just for Microservices

CAP: Challenge for Replication

Page 77: Data Architecture not Just for Microservices

CAP Theorem> Consistency

> All nodes see the same data

> Availability

> Node failures do not prevent survivors from operating

> Partition Tolerance

> System continues to operate despite arbitrary message loss

C

P A

Page 78: Data Architecture not Just for Microservices

CAP Theorem: P

> Network partitions do occur

> Even with highly available network hardware

> Also: very slow response = partition

> Need to deal with P

Page 79: Data Architecture not Just for Microservices

CAP Theorem: C or A?> Node cannot access other nodes

> Might have missed updates

> A, not C:Answer with a potentially wrong answer

> C, not A:Don’t answer – the answer might be wrong

Page 80: Data Architecture not Just for Microservices

Billing OrderProcess

CRM

SharedKernelOrder

SharedKernelOrder

SharedKernelOrder

Additionaldata

Additionaldata

Additionaldata

New Order Event

inconsistent or unavailable

Page 81: Data Architecture not Just for Microservices

Conclusion

Page 82: Data Architecture not Just for Microservices

Classic:CentralizedDatabase

Microservices:private

databasedecoupling

Data Microservices:Consistent but

resilience / performance/ transactions / decoupling?

Database perMicroservice:

Polyglot Persistence

Schema perMicroservice:

Simple infrastructure

Page 83: Data Architecture not Just for Microservices

Redundant Data orBounded Context?

Batch

DatabaseReplication

Events

Redundancy?Context Map andContext Relations Replication

CAP

EventSourcingCQRS

e.g. SharedKernel

Page 84: Data Architecture not Just for Microservices

Decentralize data!

Page 85: Data Architecture not Just for Microservices

EMail [email protected] to get:Slides+ Microservices Primer+ Sample Microservices Book+ Sample of Continuous Delivery Book

Powered by Amazon Lambda & Microservices