Top Banner
Data Architecture – Not Just for Microservices Eberhard Wolff @ewolff Fellow
82

Data Architecturen Not Just for Microservices

Jan 06, 2017

Download

Software

Eberhard Wolff
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Data Architecturen Not Just for Microservices

Data Architecture –Not Just for

MicroservicesEberhard Wolff

@ewolffFellow

Page 2: Data Architecturen Not Just for Microservices

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

Page 3: Data Architecturen Not Just for Microservices

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

Page 4: Data Architecturen Not Just for Microservices

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

FREE!!!!

Page 5: Data Architecturen 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 6: Data Architecturen Not Just for Microservices

Classic Data Architecture

Billing OrderProcess CRM

Order

Page 7: Data Architecturen Not Just for Microservices

Who is using a centralized database?

Page 8: Data Architecturen Not Just for Microservices

Who likes thecentralized database?

Page 9: Data Architecturen 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 10: Data Architecturen Not Just for Microservices

Microservices: Definition

Server /Container

Server / Container

MicroService

MicroService

Page 11: Data Architecturen 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 12: Data Architecturen Not Just for Microservices

Microservices aim for decoupling

Page 13: Data Architecturen Not Just for Microservices

Microservices & Data

Server /Container

Server / Container

MicroService

MicroService

Order Schema

Page 14: Data Architecturen Not Just for Microservices

Microservices & Data

Server /Container

Server / Container

MicroService

MicroService

Order Schema

Page 15: Data Architecturen Not Just for Microservices

Microservices & Data

> Decoupling for data, too

> Separate data storage

Page 16: Data Architecturen Not Just for Microservices

Data Microservices

Server /Container

Server / Container

MicroService

MicroService

Order DataMicroservice

Page 17: Data Architecturen Not Just for Microservices

Data Microservices

Server /Container

MicroService

Order DataMicroservice

Customer DataMicroservice

Remote callsinfluence

performanceavailability

No transactionacross customer

and order

Page 18: Data Architecturen Not Just for Microservices

Data Microservice

> Change two microservices if new feature requires change to data schema

> But: data in one place

> No consistency issues

Page 19: Data Architecturen Not Just for Microservices

Data microservice limits decoupling.

Page 20: Data Architecturen 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 21: Data Architecturen Not Just for Microservices

Violates Encapsulation

Billing OrderProcess CRM

OrderShared

data model

Logic

Page 22: Data Architecturen Not Just for Microservices

Violates Encapsulation

Server /Container

Server / Container

MicroService

MicroService

Order DataMicroservice Shared

data model

Logic

Page 23: Data Architecturen Not Just for Microservices

Separate Databases

Server /Container

Server / Container

MicroService

MicroService

Order Order

Page 24: Data Architecturen Not Just for Microservices

Different Databases

Server /Container

Server / Container

MicroService

MicroService

neo4j Oracle

Page 25: Data Architecturen 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 26: Data Architecturen Not Just for Microservices

Separate Schema

Server /Container

Server / Container

MicroService

MicroService

OracleSchema Schema

Page 27: Data Architecturen Not Just for Microservices

Separate Schemas

> Less effort

> Decoupled data models

> ...but limited independent scaling and robustness

Page 28: Data Architecturen Not Just for Microservices

Billing OrderProcess CRM

OrderOrder Order

Page 29: Data Architecturen Not Just for Microservices

Redundancy!!!

Page 30: Data Architecturen Not Just for Microservices
Page 31: Data Architecturen Not Just for Microservices
Page 32: Data Architecturen Not Just for Microservices

Domain-driven Design

Page 33: Data Architecturen 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 34: Data Architecturen Not Just for Microservices

Order

Shipping addressTracking #ItemsItem CategoriesPriority shippingCustoms #Account #

...Credit card #

Order #

Page 35: Data Architecturen Not Just for Microservices

My Domain Modelis a mess!

Page 36: Data Architecturen 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 37: Data Architecturen Not Just for Microservices

Order

Shipping address

Tracking #

Items

Item Categories

Priority shipping

Customs #

Account #

...

Credit card #

Order #

Customs

Order

Recommen-dations

Order

Tracking

Order

ShippingaddressTracking #

ItemCategories

Priorityshipping

Customs #

Payment

Order

Account #Credit card #

Page 38: Data Architecturen Not Just for Microservices

Billing OrderProcess CRM

OrderOrder Order

Page 39: Data Architecturen Not Just for Microservices

Bounded Context

> Microservice =BOUNDED CONTEXTS

> Changes for new features are local

> …even if data models need to be changed

Page 40: Data Architecturen Not Just for Microservices

Billing OrderProcess CRM

OrderOrder Order

Page 41: Data Architecturen Not Just for Microservices

Redundancy?

Page 42: Data Architecturen Not Just for Microservices

Redundancy?Not really

Page 43: Data Architecturen Not Just for Microservices

Bounded Context

Page 44: Data Architecturen Not Just for Microservices

What aboutbasic data of an

order?

Page 45: Data Architecturen Not Just for Microservices

Strategic Design

> How do BOUNDED CONTEXTS relate to each other?

> Context can have relationships

> DDD defines several relationship patterns

Page 46: Data Architecturen 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 47: Data Architecturen 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 48: Data Architecturen 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 49: Data Architecturen Not Just for Microservices

CoordinationEffort

Shared BOUNDED CONTEXT

SHARED KERNEL

CUSTOMER / SUPPLIER

ANTICORRUPTION LAYER

CONFORMIST

SEPARATE WAYS

Page 50: Data Architecturen Not Just for Microservices

Context Map

Page 51: Data Architecturen 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 52: Data Architecturen 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 53: Data Architecturen Not Just for Microservices

Billing OrderProcess

CRM

SharedKernelOrder

Additionaldata

Additionaldata

Additionaldata

OrderData

Page 54: Data Architecturen 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 55: Data Architecturen Not Just for Microservices

Billing OrderProcess

CRM

SharedKernelOrder

SharedKernelOrder

SharedKernelOrder

Additionaldata

Additionaldata

Additionaldata

Page 56: Data Architecturen 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 57: Data Architecturen Not Just for Microservices

How to Replicate Data?

Page 58: Data Architecturen 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 59: Data Architecturen Not Just for Microservices

Replication with Events

Page 60: Data Architecturen 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 61: Data Architecturen Not Just for Microservices

Billing OrderProcess

CRM

SharedKernelOrder

SharedKernelOrder

SharedKernelOrder

Additionaldata

Additionaldata

Additionaldata

New Order Event

Page 62: Data Architecturen 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 63: Data Architecturen Not Just for Microservices

More Fun With Events

Page 64: Data Architecturen Not Just for Microservices

Event Sourcing

> Internal Structure for Microservice with events

> Current state result of all events

> Calculate state on the fly?

Page 65: Data Architecturen Not Just for Microservices

Event Queue

Event

Event

Event

EventHandler

EventHandler

EventStore

Snapshot

Page 66: Data Architecturen Not Just for Microservices

Event Sourcing

> Event store and snapshot help to repair inconsistencies

> Event-based architecture in microservices

Page 67: Data Architecturen 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 68: Data Architecturen Not Just for Microservices

Commands vs Events

> Command: Change that data!

> Event: Something has happened

> Component decides if data should be changed

Page 69: Data Architecturen Not Just for Microservices

CommandQueue

Command

Command

Command

CommandHandler

QueryHandler

CommandStore

Database

Page 70: Data Architecturen Not Just for Microservices

Batch Replication

Page 71: Data Architecturen Not Just for Microservices

Batch

> Get all data

> Provide API

> …to decouple schema

> Copy interesting data into local database

Page 72: Data Architecturen Not Just for Microservices

Billing OrderProcess

CRM

SharedKernelOrder

SharedKernelOrder

SharedKernelOrder

Additionaldata

Additionaldata

Additionaldata

BatchBatch API API

Page 73: Data Architecturen 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 74: Data Architecturen Not Just for Microservices

CAP: Challenge for Replication

Page 75: Data Architecturen 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 76: Data Architecturen 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 77: Data Architecturen 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 78: Data Architecturen Not Just for Microservices

Billing OrderProcess

CRM

SharedKernelOrder

SharedKernelOrder

SharedKernelOrder

Additionaldata

Additionaldata

Additionaldata

New Order Event

inconsistent or unavailable

Page 79: Data Architecturen Not Just for Microservices

Conclusion

Page 80: Data Architecturen 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 81: Data Architecturen Not Just for Microservices

Redundant Data orBounded Context?

Batch

DatabaseReplication

Events

Redundancy?Context Map andContext Relations Replication

CAP

EventSourcingCQRS

e.g. SharedKernel

Page 82: Data Architecturen Not Just for Microservices

Decentralize data!