98
Microservice Architectures Angelo Corsaro, PhD Chief Technology Officer [email protected] with Part-I

Microservice Architectures with PrismTech Vortex

Embed Size (px)

Citation preview

Page 1: Microservice Architectures with PrismTech Vortex

Microservice Architectures

AngeloCorsaro,PhDChiefTechnologyOfficer

[email protected]

with

Part-I

Page 2: Microservice Architectures with PrismTech Vortex

Microservice architectures are on of the latest buzz in software architectures

Let’s try to understand what microservices are and how to build microservice architectures

Page 3: Microservice Architectures with PrismTech Vortex

microserviceS “Microservices are small, autonomous services that work together.” [1]

Page 4: Microservice Architectures with PrismTech Vortex

microservice Architectural

style

“The microservice architectural style is an approach to developing a single

application as a suite of small services, each running in its own

process and communicating with lightweight mechanisms.” [2]

Page 5: Microservice Architectures with PrismTech Vortex

Monolith vs.

microservice

A good way of getting the gist of the microservice architectural style is to

compare it to the more traditional monolithic approach

Page 6: Microservice Architectures with PrismTech Vortex

Monolithic Architectures

Page 7: Microservice Architectures with PrismTech Vortex

Monolithic Architectures

Traditional 3 -Tier architectures with

decomposition based on Technology / Skills

boundaries and modularisation based on

libraries

Client Tier (UI)

Server Tier

Data Tier

Page 8: Microservice Architectures with PrismTech Vortex

Monolithic Architectures

A monolithic applications merges multiple

functionalities in the same executable

Server Tier

Process

Functionality

Page 9: Microservice Architectures with PrismTech Vortex

ChallengesScaling monolithic

applications is challenging as we have just one degree

of freedom to scale out

The same challenge applies to replication

Server Tier

Load Balancer

Page 10: Microservice Architectures with PrismTech Vortex

Server Tier

ChallengesInnovation is constrained by the fact that we cannot

easily mix different technologies for

implementing the various functionalities

Same Technology Stack

Page 11: Microservice Architectures with PrismTech Vortex

Server Tier

ChallengesIncremental Change is

constrained by the fact that can’t incrementally

deploy new functionalities . We need

to redeploy an entire subsystem. Hard to hide internal

details and limit dependencies

Page 12: Microservice Architectures with PrismTech Vortex

ChallengesLoose Coupling and High

Cohesion are harder to achieve and especially to

preserve as the “barriers” between functionalities are

very thin

Server Tier

Module / Library Boundaries

Page 13: Microservice Architectures with PrismTech Vortex

Microservice Architectures

Page 14: Microservice Architectures with PrismTech Vortex

Server Tier

ProcessFunctionality

Microservice ArchitecturesIndividual functionalities

become unit of deployment and run in

their own process

Page 15: Microservice Architectures with PrismTech Vortex

Microservice Architectures

Microservices communicate through

some lightweight mechanism

Server Tier

ProcessFunctionality

Page 16: Microservice Architectures with PrismTech Vortex

Server Tier

BenefitsScaling microservice

applications is easier as we can scale out individual

functionalities

Page 17: Microservice Architectures with PrismTech Vortex

BenefitsUnconstrained Innovation

as we choose the technologies stack that

makes the most sense for implementing a given

feature

Server Tier

ProcessFunctionality

Page 18: Microservice Architectures with PrismTech Vortex

Incremental Change is facilitated allowing

incremental deployment of new functionalities.

Potentially different version of the same micro service could be running at the same time!

Benefits Server Tier

ProcessFunctionality

Page 19: Microservice Architectures with PrismTech Vortex

Loose Coupling and High Cohesion are easier to

achieved to preserve as the “barriers” between functionalities are very

thick

Server Tier

Process Boundary / Share Nothing

Benefits

Page 20: Microservice Architectures with PrismTech Vortex

Performance of microservice architectures

may be degraded by the higher cost of

communication if the right technology is not used

Server Tier

ChallengesMonolithic

Implementation

Microservice Implementation

In-Process Communication

Inter-Process/Host Communication

Page 21: Microservice Architectures with PrismTech Vortex

Deployment and Operation of systems

based on the microservice architectures is inherently more complex, especially

at scale and when the right technologies are not used

Server Tier

ChallengesMonolithic

Implementation

Microservice Implementation

Page 22: Microservice Architectures with PrismTech Vortex

Designing Microservice Architectures

Page 23: Microservice Architectures with PrismTech Vortex

Identifying Microservices

Microservices are supposed to capture business and not

technical features of a system

Microservices

Page 24: Microservice Architectures with PrismTech Vortex

Identifying Microservices

When a monolithic systems is already existing, micro

services can be created by separating the various

features

Microservices

Page 25: Microservice Architectures with PrismTech Vortex

When a system does not exist we can use the Bounded Context as defined in [3]

System Objectives

Microservices

Identifying Microservices Bounded Context

Page 26: Microservice Architectures with PrismTech Vortex

Bounded ContextDomain-Driven Design (DDD) divides a complex domain into a series of

Bounded Context. Where a context means a specific system responsibility, and a bounded context means that responsibility is

enforced with explicit boundaries.

Each bounded context has its own canonical model and communication between bounded context happens through a system-

canonic al model

Page 27: Microservice Architectures with PrismTech Vortex

Microservices are ideally mapped to Bounded Context.

Each Bounded context has potentially its own canonical model

Communication between Bounded Context uses the system-wide

canonical model

Microservicesbounded context

micro-service canonical model

system canonical model

Page 28: Microservice Architectures with PrismTech Vortex

A consequence of applying the Bounded Context technique is

that data management in micro services architectures is

decentralised

Decentralised Data Management

bounded context

micro-service canonical model

system canonical model

Page 29: Microservice Architectures with PrismTech Vortex

Every microservice owns and manages its data without relying

on a shared data-base.

Consequently microservice architectures are build under

eventual consistency assumptions

Decentralised Data Management

bounded context

micro-service canonical model

system canonical model

Page 30: Microservice Architectures with PrismTech Vortex

Any organisation that designs a system (defined broadly) will produce a design whose structure is a copy of the organization's communication structure.

— M. Conway, 1967

Conway’s Law

Page 31: Microservice Architectures with PrismTech Vortex

Conway’s tells us that to be successful in applying

microservice architectures we should have cross-functional

teams organised around business capabilities

Conway’s LAW Implications

image curtesy of M. Fowler http://martinfowler.com/articles/microservices.html

Page 32: Microservice Architectures with PrismTech Vortex

(This is an adaptation of a Figure from [1])

Microservices small autonomous

services

Modelled around business concepts

Highly Automated

Hide internal implementation

details

Decentralised

Independent DeploymentFailure Isolation

Highly Observable

Page 33: Microservice Architectures with PrismTech Vortex

Vortex Overview

Page 34: Microservice Architectures with PrismTech Vortex

Vortex's Coordination Model

Page 35: Microservice Architectures with PrismTech Vortex

Applications can autonomously and asynchronously read and

write data enjoying spatial and temporal decoupling

DDS Global Data Space

...

Data Writer

Data Writer

Data Writer

Data Reader

Data Reader

Data Reader

Data Reader

Data Writer

TopicAQoS

TopicBQoS

TopicCQoS

TopicDQoS

Global Data Space

Page 36: Microservice Architectures with PrismTech Vortex

Built-in dynamic discovery isolates applications from

network topology and connectivity details

DDS Global Data Space

...

Data Writer

Data Writer

Data Writer

Data Reader

Data Reader

Data Reader

Data Reader

Data Writer

TopicAQoS

TopicBQoS

TopicCQoS

TopicDQoS

Dynamic Discovery

Page 37: Microservice Architectures with PrismTech Vortex

Topic

Page 38: Microservice Architectures with PrismTech Vortex

A domain-wide information’s class A Topic defined by means

of a <name, type, qos>

TopicDDS Global Data Space

...

Data Writer

Data Writer

Data Writer

Data Reader

Data Reader

Data Reader

Data Reader

Data Writer

TopicAQoS

TopicBQoS

TopicCQoS

TopicDQoS

TopicTypeName

QoS

Page 39: Microservice Architectures with PrismTech Vortex

Topic Types

Page 40: Microservice Architectures with PrismTech Vortex

Topic Types: Language Independent

Definitions

Page 41: Microservice Architectures with PrismTech Vortex

Topic types can be expressed using different syntaxes,

including IDL and ProtoBuf

Topic Type struct CarDynamics { string cid; long x; long y; float dx; long dy; } #pragma keylist CarDynamics cid

IDL

Page 42: Microservice Architectures with PrismTech Vortex

Topic types can be expressed using different syntaxes,

including IDL and ProtoBuf

Topic Type message CarDynamics { option (.omg.dds.type) = {name: "CarDynamics"}; required string cid = 0 [(.omg.dds.member).key = true]; required long x = 1; required long y = 2; required float dx = 3; required long dy = 4; }

ProtoBuf

Page 43: Microservice Architectures with PrismTech Vortex

Topic Types: Language Specific

Definitions

Page 44: Microservice Architectures with PrismTech Vortex

Topic types can be expressed using different syntaxes,

including IDL and ProtoBuf

Topic Type class CarDynamics: constructor: (@cid, @x, @y, @dx, @dy) ->

CoffeeScript

Page 45: Microservice Architectures with PrismTech Vortex

Topic types can be expressed using different syntaxes,

including IDL and ProtoBuf

Topic Type public struct CaDynamics { public string cid { get; set; } public int x { get; set; } public int y { get; set; } public int dx { get; set; } public int dy { get; set; } public CaDynamics (string cid, int x, int y, int dx, int dy) { this.cid = cid; this.x = x; this.y = y; this.dx = dx; this.dy = dy; } }

C#

Page 46: Microservice Architectures with PrismTech Vortex

Topic types can be expressed using different syntaxes,

including IDL and ProtoBuf

Topic Type @KeyList ( topicType = "CarDynamics", keys = {"cid"})public class CarDynamics { public String cid; public int x; public int dx; public int y; public int dy; public CarDynamics(String s, int a, int b, int c,int d) { this.cid = s; this.x = a; this.dx = b; this.y = c; this.dy = d; } @Override public String toString() { … }}

Java

Page 47: Microservice Architectures with PrismTech Vortex

TopicAQoS

TopicCQoS ...

TopicBQoS

TopicDQoS

PartitionsThe Global Data Space can be

divided in to arbitrary partitions

The source and destination of data is identified by means of “Partition/Topic” expressions

“Red”

“Blue”

Page 48: Microservice Architectures with PrismTech Vortex

QoS policies allow to express temporal and availability

constraints for data

DDS Global Data Space

...

Data Writer

Data Writer

Data Writer

Data Reader

Data Reader

Data Reader

Data Reader

Data Writer

TopicAQoS

TopicBQoS

TopicCQoS

TopicDQoS

QoS - Enabled

Page 49: Microservice Architectures with PrismTech Vortex

A collection of policies that control non-

functional properties such as reliability,

persistence, temporal constraints and priority

QoS

HISTORY

LIFESPAN

DURABILITY

DEADLINE

LATENCY BUDGET

TRANSPORT PRIO

TIME-BASED FILTER

RESOURCE LIMITS

USER DATA

TOPIC DATA

GROUP DATA

OWENERSHIP

OWN. STRENGTH

LIVELINESS

ENTITY FACTORY

DW LIFECYCLE

DR LIFECYCLE

PRESENTATION

RELIABILITY

PARTITION

DEST. ORDER

RxO QoS Local QoS

Page 50: Microservice Architectures with PrismTech Vortex

QoS Policies controlling end-to-end properties

follow a Request vs. Offered

QoS Domain

Participant

DURABILITY

OWENERSHIP

DEADLINE

LATENCY BUDGET

LIVELINESS

RELIABILITY

DEST. ORDER

Publisher

DataWriter

PARTITION

DataReader

Subscriber

DomainParticipant

offered QoS

Topicwrites reads

Domain Idjoins joins

produces-in consumes-from

RxO QoS Policies

requested QoS

Page 51: Microservice Architectures with PrismTech Vortex

Interacting with the Data Cache

Page 52: Microservice Architectures with PrismTech Vortex

Each Data Reader is associated with a Cache

The Cache stores the last n∊𝜨∞ samples for each

relevant instance

Data Cache

DataReader Cache

DataReader

...

Samples

Instances

Cache

Where: 𝜨∞=𝜨 ∪ {∞}

Page 53: Microservice Architectures with PrismTech Vortex

The action of reading samples for a Reader Cache

is non-destructive.

Samples are not removed from the cache

Reading Data

DataReader Cache

DataReader

...

DataReader Cache

DataReader

...read

Page 54: Microservice Architectures with PrismTech Vortex

The action of taking samples for a Reader Cache

is destructive.

Samples are removed from the cache

Taking Data

DataReader Cache

DataReader

...

DataReader Cache

DataReader

...take

Page 55: Microservice Architectures with PrismTech Vortex

Samples can be selected using composable content

and status predicates

Sample Selectors

DataReader Cache

DataReader

...

Page 56: Microservice Architectures with PrismTech Vortex

Filters allow to control what gets into a DataReader

cache

Filters are expressed as SQL where clauses or as

Java/C/JavaScript predicates

Content-Filtering

DataReader Cache

DataReader

...

Filter

Application

Network

Page 57: Microservice Architectures with PrismTech Vortex

Content Filters can be used to project on the

local cache only the Topic data

satisfying a given predicate

Content Filters structCarDynamics{

@keystringcid;longx;longy;floatdx;longdy;}

cid x y dx dyGR 33N GO 167 240 45 0LO 00V IN 65 26 65 0AN 637 OS 32 853 0 50AB 123 CD 325 235 80 0

“dx>50ORdy>50”

Type

CarDynamics

cid x y dx dyLO 00V IN 65 26 65 0AB 123 CD 325 235 80 0

Reader Cache

Page 58: Microservice Architectures with PrismTech Vortex

Queries allow to control what gets out of a

DataReader Cache

Queries are expressed as SQL where clauses or as

Java/C/JavaScript predicates

Content-Based Selection

DataReader Cache

DataReader

...

Query

DataReader Cache

DataReader

...

Application

Network

Page 59: Microservice Architectures with PrismTech Vortex

Reader Cache

Queries can be used to select out of the local cache

the data matching a given predicate

QueriesstructCarDynamics{@keystringcid;longx;longy;floatdx;longdy;}

cid x y dx dyGR 33N GO 167 240 45 0LO 00V IN 65 26 65 0AN 637 OS 32 853 0 50AB 123 CD 325 235 80 0

“dx>50ORdy>50”

Type

CarDynamics

cid x y dx dyGR 33N GO 167 240 45 0LO 00V IN 65 26 65 0AN 637 OS 32 853 0 50AB 123 CD 325 235 80 0

cid x y dx dyLO 00V IN 65 26 65 0AB 123 CD 325 235 80 0

query

Page 60: Microservice Architectures with PrismTech Vortex

State based selection allows to control what gets out of a DataReader Cache

State base selectors predicate on samples meta-

information

State-Based Selection

DataReader Cache

DataReader

...

State Selector

DataReader Cache

DataReader

...

Application

Network

Page 61: Microservice Architectures with PrismTech Vortex

Selector Example

// == ISO C++ DDS API ==

auto data = dr.select() .content(query) .state(data_state) .instance(handle) .read();

Page 62: Microservice Architectures with PrismTech Vortex

your first vortex app

Page 65: Microservice Architectures with PrismTech Vortex

Cop

yrig

ht P

rism

Tech

, 201

5

Reading Data in C++#include <dds.hpp>

int main(int, char**) {

DomainParticipant dp(0); Topic<Meter> topic(”SmartMeter”); Subscriber sub(dp); DataReader<Meter> dr(dp, topic);

LambdaDataReaderListener<DataReader<Meter>> lst; lst.data_available = [](DataReader<Meter>& dr) { auto samples = data.read(); std::for_each(samples.begin(), samples.end(), [](Sample<Meter>& sample) { std::cout << sample.data() << std::endl; } } dr.listener(lst); // Print incoming data up to when the user does a Ctrl-C std::this_thread::join(); return 0; }

enumUtilityKind{ ELECTRICITY, GAS, WATER};structMeter{ stringsn; UtilityKindutility; floatreading; floaterror;};#pragmakeylistMetersn

Page 70: Microservice Architectures with PrismTech Vortex

Vortex Technology Stack

Page 71: Microservice Architectures with PrismTech Vortex

Device implementations optimised for OT, IT and

consumer platforms

Native support for Cloud and Fog Computing Architectures

Device-2-DeviceDevice-2-Cloud

Fog-2-Cloud

Device-2-Fog

Cloud-2-Cloud

Fog-2-Fog

infra

stru

ctur

esd

k

Page 72: Microservice Architectures with PrismTech Vortex

Vortex-Based Microservices

Page 73: Microservice Architectures with PrismTech Vortex

Microservices are ideally mapped to Bounded Context.

Each Bounded context has potentially its own canonical model

Communication between Bounded Context uses the system-wide

canonical model

Bounded contextbounded context

micro-service Vortex Data Model

system canonical Vortex Data model

Page 74: Microservice Architectures with PrismTech Vortex

micro-service partition

system partition

micro-service data model

system (inter-svc) data model

Page 75: Microservice Architectures with PrismTech Vortex

Benefits

Page 76: Microservice Architectures with PrismTech Vortex

Decentralised Infrastructure

Page 77: Microservice Architectures with PrismTech Vortex

The relevant portion of the data space is projected on the

application address space. Each typed projection is commonly called

a Cache

No single point of failure or bottleneck

No central server to configure/ manage

Decentralised Data Space

Data Writer

Data Writer

Data Writer

Data Reader

Data Reader

Data Reader

Data Writer

TopicAQoS

TopicBQoS

TopicCQoS

TopicDQoS

TopicDQoS

TopicDQoS

TopicAQoS

Page 78: Microservice Architectures with PrismTech Vortex

Persistence

Page 79: Microservice Architectures with PrismTech Vortex

Vortex provides a high performance distributed

durability service that can be used to achieve different level

of temporal decoupling

Durability Services take ownership for “Partition/Topic “

expressions

Distributed Durability

Page 80: Microservice Architectures with PrismTech Vortex

Performance

Page 81: Microservice Architectures with PrismTech Vortex

High Performance 30 μs peer-to-peer latency

7 μs inter-core latency

4+ Mmsgs/sec p2p throughput

Device-2-DeviceDevice-2-Cloud

Fog-2-Cloud

Device-2-Fog

Cloud-2-Cloud

Fog-2-Fog

infra

stru

ctur

esd

k

Page 82: Microservice Architectures with PrismTech Vortex

>10 μs fog/cloud routing latency

High Performance Device-2-DeviceDevice-2-Cloud

Fog-2-Cloud

Device-2-Fog

Cloud-2-Cloud

Fog-2-Fog

infra

stru

ctur

esd

k

Page 83: Microservice Architectures with PrismTech Vortex

Deployment Fexibility

Page 84: Microservice Architectures with PrismTech Vortex

Microservice deployment

The common guideline for Microservices is to deploy

them across different hosts to limit the impact of a

failing machine

Page 85: Microservice Architectures with PrismTech Vortex

Microservice deployment

The one micro-service per host rule can be

constraining in terms of performance

Page 86: Microservice Architectures with PrismTech Vortex

Microservice deployment

Vortex location transparency and intra-host

communication optimisation allow to exploit the benefits

of micro-service architectures without major

performance costsUltra-Low Latency

Inter-Process Comm

Page 87: Microservice Architectures with PrismTech Vortex

Technology Agnostic

Page 88: Microservice Architectures with PrismTech Vortex

Vortex is a Polyglot and Interoperable across

Programming Languages Device-2-DeviceDevice-2-Cloud

Fog-2-Cloud

Device-2-Fog

Cloud-2-Cloud

Fog-2-Fog

infra

stru

ctur

esd

k

Page 89: Microservice Architectures with PrismTech Vortex

Fully Independent of the Cloud Infrastructure

Private Clouds

Device-2-DeviceDevice-2-Cloud

Fog-2-Cloud

Device-2-Fog

Cloud-2-Cloud

Fog-2-Fog

infra

stru

ctur

esd

k

Page 90: Microservice Architectures with PrismTech Vortex

Native Integration with the hottest real-time analytics

platforms and CEP Device-2-DeviceDevice-2-Cloud

Fog-2-Cloud

Device-2-Fog

Cloud-2-Cloud

Fog-2-Fog

infra

stru

ctur

esd

k

Page 91: Microservice Architectures with PrismTech Vortex

Integration with mainstream Dashboard Technologies

Device-2-DeviceDevice-2-Cloud

Fog-2-Cloud

Device-2-Fog

Cloud-2-Cloud

Fog-2-Fog

infra

stru

ctur

esd

k

Page 92: Microservice Architectures with PrismTech Vortex

Native Support for Microservices

Patterns

Page 93: Microservice Architectures with PrismTech Vortex

TimeoutAs a general rule Vortex APIs

are non-blocking

Blocking API calls are all equipped with timeout

#include <dds.hpp>

int main(int, char**) {

DomainParticipant dp(0); Topic<Meter> topic(“SmartMeter”); Publisher pub(dp); DataWriter<Meter> dw(pub, topic);

while (!done) { auto value = readMeter() dw.write(value); std::this_thread::sleep_for(SAMPLING_PERIOD); }

return 0; }

Page 94: Microservice Architectures with PrismTech Vortex

Worker PatternVortex provides several ways of supporting the

worker pattern

Page 95: Microservice Architectures with PrismTech Vortex

CIRCUIT BREAKERVortex communications primitive implement the

circuit breaker pattern thus reducing the complexity of

adopting it

Page 96: Microservice Architectures with PrismTech Vortex

Microservices architectures bring several architectural benefits

Vortex ensures that the operational and performance cost of adopting micro services architectures if minimised

In Summary

Page 98: Microservice Architectures with PrismTech Vortex

Cop

yrig

ht P

rism

Tech

, 201

5