Micro service architecture

42
SERVICES - ARCHITECTURE Governance Team 10 Mar 17

Transcript of Micro service architecture

Page 1: Micro service architecture

SERVICES - ARCHITECTURE

Governance Team 10 Mar 17

Page 2: Micro service architecture

• Traditional Approach • Issues in Traditional • Define MS• Characteristics of

MSA• Service Discovery• Communication /Integration in MS

– MSA

Page 3: Micro service architecture

• Data Management in MS

• Deployment Strategy • Migration to MSA• PROS & Cons of MSA• Best Practices of MSA• Demo• QA

– MSA

Page 4: Micro service architecture

Monolith – Architecture• Monolithic means

composed all in one piece. Monolithic software is designed to be self-contained.

• Components of the program are interconnected and interdependent (tightly coupled)

Page 5: Micro service architecture

Monolith Characteristics• Extensibility is bit difficult since the code base is

very huge • Slow down the development and takes more

time to shipping the new features • CD – Impossible Task • Difficult to scale • Application Reliability • Long Term commitment in Technology Stack

Page 6: Micro service architecture

Micro Service Architecture-MSA

• Small, and Focused on Doing One Thing Well• Software applications as a suite of Independently

deployable, small, modular services in which each service runs a unique process and communicates through a well-defined, lightweight mechanism to serve a business goal

• Large functionality or business capability is decomposed into set of small services

Page 7: Micro service architecture

MSA – Characteristics

• Componentization via Services• Organized around Business Capabilities• Decentralized Governance• Products not Projects• Decentralized Data Management• Infrastructure Automation• Design for failure• Evolutionary Design(From Martin Fowler’s Link)

Page 8: Micro service architecture

MSA – Interaction Style• Services are interacted using Inter process communication (IPV)Mechanism.IPC : One to one /One to Many Sync/Async

Page 9: Micro service architecture

MSA – Interaction Style

IPC Style One to One One to Many

Sync Request /Response

Async Notification Publish /Subscribe

Request/Async Response Publish/Async Response

Page 10: Micro service architecture

MSA – Interaction Style Sample

Page 11: Micro service architecture

MSA – Service Discovery

Page 12: Micro service architecture

MSA – Service Discovery

• Client Side Discovery Pattern • Server Side Discovery Pattern

Page 13: Micro service architecture

MSA – Client Side Service Discovery

Page 14: Micro service architecture

MSA – Server Side Service Discovery

Page 15: Micro service architecture

MSA – Data Management

• Challenge in MSA Data Management– Since MSA handling the different DB with different

services the following challenges we are facing in the Data management Context• Transaction Management-2PC/Distributed Transaction • Retrieve the Data from Multiple DB

Page 16: Micro service architecture

Event Driven Architecture

• You can use the events to implements Business transaction that span of Multiple Services

• Its not ACID Transaction instead its BASE Model • Its guarantees such as eventually consistency

Page 17: Micro service architecture

Event Driven Architecture-

• Steps to Perform the Transaction in EDA– Update the Business entity and publish the event from

Service1– Publish the events into Message Broker– Service 2 consume the event , update the business entity

based on the event – Service 2 publish another event in the Message Broker – Service 1 consume the event and update the status in

their DB

Page 18: Micro service architecture

Event Driven Architecture-Flow

Page 19: Micro service architecture

Event Driven Architecture-FlowMaterialized View :

Read the data from Multiple DB Data is always eventually consistent.

Page 20: Micro service architecture

Atomicity in MSAAchieving Atomicity in following ways Publishing event using local transaction Mining a Database Transaction log Event Sourcing DB Link/Trigger

Page 21: Micro service architecture

Deployment StrategyMSA Deployment Patterns:

Multiple Service Instance /Host PatternService Instance /Host Pattern

Service Instance /VMService Instance/Container

Serverless Deployment Pattern

Page 22: Micro service architecture

Migration StrategyFollowing strategy for Monolith MSA Migration• Stop Digging code –

• No further extension in the Monolith instead create the separate service for those new requirement

• Using glue code for internal integration between service and monolith• Separate the Frontend and Backend layer

• Separate the Presentation layer with Business /Data Layer • Communication between those layers through IPC

• Extract the Module from Monolith • Extract the key module from monolith and convert into service

Page 23: Micro service architecture

MSA Design PatternAggregator DPProxy DPShared Data DPASync Message DPChain DPBranch DP

Page 24: Micro service architecture

API Gateway

Page 25: Micro service architecture

PROS -MSA

• Independent Deployment and Development• Code and Team size not grow rapidly • Define the services based on Business capability • Reliability • Easy to Scale • No long-term commitment to technology stack

Page 26: Micro service architecture

Cons -MSA

• Complexity in terms of Architect/Testing/Deployment

• Increasing number of services will cause the Memory /Resource/ Maintenance issue

• Communication between the services bit complex • Duplication effort

Page 27: Micro service architecture

Demo – Technology

• Java 8• Spring Boot • Spring Cloud • Postgresql • Cloud Foundry• Eureka • Maven

Page 28: Micro service architecture

Demo

• Restful Service• Restful with DB• IPC Demo

Page 29: Micro service architecture

QUESTIONS?

Page 30: Micro service architecture

APPENDIX

Page 31: Micro service architecture

Handling Partial Failure • Network Timeout • Limiting number of outstanding request- Throttling• Circuit Broker Pattern • Provide the Fallback – – Perform fall back logic when a request fails. For example,

return cached data or a default value, such as an empty set of recommendations

Page 32: Micro service architecture

Message Channels• Point 2 Point – delivers a message to exactly one of the consumers that

are reading from the channel– IPC – One –to – One

• Publish – Subscribe – delivers each message to all of the attached consumers.– IPC – One –to-Many

Page 33: Micro service architecture

HATEOAS

Page 34: Micro service architecture

MSA-Chassis

• Its framework, which handles cross-cutting concerns like logging/Security/Health check/Externalize the configuration file,Service registration/service discovery and etc

Page 35: Micro service architecture

Service Registry

• Key Part of Service Discovery• Its DB containing the network location of

services instance• Tools /API used to register the services in

Registry• Ex:– Etcd– Consul– Apache ZooKeeper

Page 36: Micro service architecture

Service Registration

• Service instances must be registered with and unregistered from the service registry

• Two ways – Self Registration– Third Party Tool Registration

Page 37: Micro service architecture

ACID

• Atomicity – – Changes are made atomically

• Consistency – – The state of the database is always consistent

• Isolation – – Even though transactions are executed

concurrently, it appears they are executed serially• Durable – – Once a transaction has committed, it is not undone

Page 38: Micro service architecture

BASE

Page 39: Micro service architecture

Polyglot Persistence

• MSA uses the mix of Database like No SQL/RBDMS and etc to store/query the different kind of data

Page 40: Micro service architecture

A|B Testing

Page 41: Micro service architecture

Single Responsibility Principle

Page 42: Micro service architecture

Demo GitHub– https://github.com/parameshnon