microservices: splitting the monolith

70
croservices: plitting the monolith Yusuf Hakan Oklay 22.02.2017

Upload: yusuf-hakan-oklay

Post on 12-Apr-2017

125 views

Category:

Engineering


6 download

TRANSCRIPT

Page 1: Microservices: Splitting the monolith

Microservices:Splitting the monolith

Yusuf Hakan Oklay

22.02.2017

Page 2: Microservices: Splitting the monolith

Microservicessmall,services

that work together

Page 3: Microservices: Splitting the monolith

Monolithic Architecture

Page 4: Microservices: Splitting the monolith

Monolithic Architecture

Page 5: Microservices: Splitting the monolith

Benefits of Monolithic Architecture• Simple to develop.• Simple to test. • Simple to deploy. • Simple to scale horizontally by running multiple copies behind a load

balancer.

Page 6: Microservices: Splitting the monolith

Drawbacks of Monolithic Architecture• Complex• Overloaded IDE • Overloaded web container• Continuous deployment is difficult• Scaling• Obstacle to scaling development• Requires a long-term commitment to a technology stack

Page 7: Microservices: Splitting the monolith

Microservice DefinitionThe 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, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies.

- James Lewis and Martin Fowler

Page 8: Microservices: Splitting the monolith

Microservices

Page 9: Microservices: Splitting the monolith

Benefits ofMicroserviceArchitecture

Page 10: Microservices: Splitting the monolith

• Tackling the complexity by decomposing application into• Faster to develop• Easier to understand• Easier to maintain • Manageable services

Page 11: Microservices: Splitting the monolith

• Small, Autonomous• Each service can be developed and deployed independently• Change without requiring consumers to change• Expose APIs

Page 12: Microservices: Splitting the monolith

• Improved fault isolation (Resilience)• Bulkheading: manage failure without having it cascade

throughout the services participating in the workflow

Page 13: Microservices: Splitting the monolith

• Technology Heterogeneity

Page 14: Microservices: Splitting the monolith

• Scaling

Page 15: Microservices: Splitting the monolith

• Organizational Alignment• Smaller teams working on smaller codabases becomes more

productive• which design systems ... are constrained to produce designs

which are copies of the communication structure Organizations of these organizations.

Page 16: Microservices: Splitting the monolith

16

Organizational Alignment

Page 17: Microservices: Splitting the monolith

• Ease of Deployment• Composability

• Reuse of functionality

• Optimizing for Replaceability

Page 18: Microservices: Splitting the monolith

What Makes a Good Service• Loose Coupling • High Cohesion• Do One Thing, and Do It Well

"This is the Unix philosophy: Write programs that do one thing

and do it well. Write programs to work together.”

Page 19: Microservices: Splitting the monolith

Inter-ProcessCommunication

Page 20: Microservices: Splitting the monolith

Inter-Process Communication• Shared Database• Synchronous Versus Asynchronous• Orchestration Versus Choreography• REST and HTTP Versus Apache Thrift

Page 21: Microservices: Splitting the monolith

21

Inter-Process Communication

Page 22: Microservices: Splitting the monolith

Shared Database• Most common form of integration• In this world, if other services want information from a service, they

reach into the database. And if they want to change it, they reach into the database

• Fastest form of integration

• Goodbye, loose coupling• Goodbye, cohesion

Page 23: Microservices: Splitting the monolith

Synchronous Versus Asynchronous

Page 24: Microservices: Splitting the monolith

Synchronous Versus Asynchronous

Synchronous Asynchronous

Page 25: Microservices: Splitting the monolith

Synchronous Versus Asynchronous

Page 26: Microservices: Splitting the monolith

Orchestration Versus ChoreographyUse Case : Customer Enrollment

• A new record is created in the loyalty points bank for the customer.• Our postal system sends out a welcome pack.• We send a welcome email to the customer.

Page 27: Microservices: Splitting the monolith

OrchestrationUse Case : Customer Enrollment

Page 28: Microservices: Splitting the monolith

ChoreographyUse Case : Customer Enrollment

Page 29: Microservices: Splitting the monolith

Message-Based Communication• Decouples the client from the service • Message buffering • Flexible client-service interactions • RabbitMQ, Apache Kafka, Apache ActiveMQ

• Additional operational complexity

Page 30: Microservices: Splitting the monolith

REST and HTTP• Representational State Transfer (REST) is an architectural style

inspired by the Web

Page 31: Microservices: Splitting the monolith

Richardson Maturity Model• Level 0: Clients of a level 0 API invoke the service by making HTTP

POST requests to its sole URL endpoint • Level 1 : API supports the idea of resources• Level 2 – A level 2 API uses HTTP verbs to perform actions: GET to

retrieve, POST to create, and PUT to update. • Level3 : HATEOAS (Hypertext As The Engine Of Application State).

Page 32: Microservices: Splitting the monolith

HATEOAS

Page 33: Microservices: Splitting the monolith

Thrift• Apache Thrift is an interesting alternative to REST • framework for writing cross- language RPC clients and servers. • supports various message formats: JSON, binary, and compact

binary • transport protocols including raw TCP and HTTP. • C++, Java, Python, PHP, Ruby, Erlang, and Node js

Page 34: Microservices: Splitting the monolith

JSON vs XML

Page 35: Microservices: Splitting the monolith

Using anAPI Gateway

Page 36: Microservices: Splitting the monolith

Simple Shopping ExampleGET api.company.com/productdetails/productId

Page 37: Microservices: Splitting the monolith

Using an API GatewayGET api.company.com/productdetails/productId

• Request Routing• Composition• Protocol Translation

• Load Balancing• Caching• Access Control• API metering• Monitoring

Page 38: Microservices: Splitting the monolith

Benefits and Drawbacks of an API Gateway• encapsulates the internal structure of the application • reduces the number of round trips between the client and application • simplifies the client code

• highly available component that must be developed, deployed, and managed • There is also a risk that the API Gateway becomes a development bottleneck

Page 39: Microservices: Splitting the monolith

ServiceDiscovery

Page 40: Microservices: Splitting the monolith

Service Discovery

A

A client or API Gateway needs help finding services

Page 41: Microservices: Splitting the monolith

The Client-Side Service Discovery

A

Clients can take on the task of discovering services

Page 42: Microservices: Splitting the monolith

The Server-Side Service Discovery

A

The load balancer queries the service registry and routes each request to an available service instance

Page 43: Microservices: Splitting the monolith

Service Registry• key part of service discovery • database containing the network locations of service instances • provides a REST API for registering and querying service instances • Netflix Eureka, etcd, Consul, Apache ZooKeeper• Kubernetes, Marathon, and AWS do not have an explicit service

registry.

Page 44: Microservices: Splitting the monolith

Self-Registration vs Third-Party Registration

• Services can handle their own registration• Simple• Not require any other system component

• But coupling

Page 45: Microservices: Splitting the monolith

Self-Registration vs Third-Party Registration

• service registrar handles the registration • services are decoupled from the service registry • centralized • Registrator, Netflix Prana

• Another component highly available

Page 46: Microservices: Splitting the monolith

Splitting the monolith

Page 47: Microservices: Splitting the monolith

Incremental Refactor• Strategy #1 – Stop Digging

Implementing new functionality as a separate service instead of adding a module to the monolith.

Page 48: Microservices: Splitting the monolith

Incremental Refactor• Strategy #2 – Split Fronted and Backend

split the presentation layer from the business logic and data access layers

Page 49: Microservices: Splitting the monolith

Incremental Refactor• Strategy #3 – Extract Services

o Finding Seamso Resource requirements

partso changing frequently

parts

Page 50: Microservices: Splitting the monolith

Database• Breaking Foreign Key Relationships

Page 51: Microservices: Splitting the monolith

Database• Shared Static Data

– Duplication– Static data as code or config file– Own service

Page 52: Microservices: Splitting the monolith

Database• Shared Mutable Data

Page 53: Microservices: Splitting the monolith

Database• Shared Table

Page 54: Microservices: Splitting the monolith

Staging the Break

Page 55: Microservices: Splitting the monolith

Transactional Boundaries

Page 56: Microservices: Splitting the monolith

Transactional Boundaries

Page 57: Microservices: Splitting the monolith

Transactional Boundaries• Try Again Later• Abort the Entire Operation• Distributed Transactions

• So What To Do?

Page 58: Microservices: Splitting the monolith

Handling Partial Failures• Timeouts• Limiting the number

of outstanding requests• Circuit breaker pattern• Provide fallbacks• Netflix Hsytrix

Page 59: Microservices: Splitting the monolith

Reporting

Page 60: Microservices: Splitting the monolith

Reporting• Data Retrieval via Service Calls• Data Pumps• Event Data Pump

Page 61: Microservices: Splitting the monolith

Reporting• Data Pumps

Page 62: Microservices: Splitting the monolith

Reporting• Event Data Pumps

Page 63: Microservices: Splitting the monolith

Microservices Trade-Offs

Page 64: Microservices: Splitting the monolith

Known Useshttps://www.infoq.com/presentations/migration-cloud-native

https://vimeo.com/29719577

http://philcalcado.com/2015/09/08/how_we_ended_up_with_microservices.html

Page 65: Microservices: Splitting the monolith

Known Uses

https://www.youtube.com/watch?v=RrX_28s70ww

https://eng.uber.com/tag/microservice/

Page 66: Microservices: Splitting the monolith

iyzico?

Page 67: Microservices: Splitting the monolith

next?

Page 68: Microservices: Splitting the monolith

• Event-Driven Architecture• Consumer-Driven Contract Testing• Containerization• Deployment• Monitoring• Security

Page 69: Microservices: Splitting the monolith

69

Resources

• Books

• Linkshttps://www.martinfowler.com/microservices/#what https://www.nginx.com/blog/introduction-to-microservices/ http://microservices.io/patterns/monolithic.html

Page 70: Microservices: Splitting the monolith

thanks22.02.2017