Microservices - Comparing with monolithic architecture
The good, the Bad and the Ugly
Xuan-Loi Vu
Vega’s Tech Department
98 Hoang Quoc Viet
Hanoi, 06 - 01 - 2017
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 1 / 24
Introduction
Table of Contents
1 Introduction
Monolithic architecture
Microservices architecture
2 Microservices in action
1 Bounded Context
2 Service discovery and Orchestration (coordination)
3 Latency and failure from dependencies
4 Availability
5 Security
6 Database
Event-Sourcing
CQRS
Distributed transaction
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 2 / 24
Introduction
Monolithic and Microservices
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 3 / 24
Introduction Monolithic architecture
Monolithic architecture
Characteristics:
one code base
usually one programming language
rarely, one application with more than two databases
deploy one WAR file (or directory hierarchy)
scale application by running multiple copies using load balancer
· · ·
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 4 / 24
Introduction Microservices architecture
Microservices architecture
Characteristics:
multiple code bases
full-stack or polygot
component’s database is independent
easy of deployment and scaling
· · ·
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 5 / 24
Introduction Microservices architecture
Pros and Cos
pros
Decentralize application so that easier maintain
Re-used component
Deployability - agility to roll out new versions
Reliability - fault affects that microservice alone and its consumers
(bulkhead)
Availability - rolling out a new version of a microservice requires little
downtime
Scalability - can be scaled independently using pools, clusters, grids
Modifiability - more flexibility to use new frameworks, libraries,
datasources, and other resources
Management - application management effort
Design autonomy - team has freedom to employ different
technologies, frameworks, and patterns
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 6 / 24
Introduction Microservices architecture
Pros and Cos - No silver bullet
cos
Determine “Bounded Context”
Deployability - more complex with many jobs, scripts, transfer areas,
and config files
Performance - communicate over the network, whereas services within
the monolith may benefit from local calls
Availability - belongs to dynamic discovery
Modifiability - database inconsistency, transaction, . . .
Testability - harder to setup and run
Management - application operation effort increases because there are
more runtime components, log files, and point-to-point interactions to
oversee
Security
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 7 / 24
Microservices in action
Table of Contents
1 Introduction
Monolithic architecture
Microservices architecture
2 Microservices in action
1 Bounded Context
2 Service discovery and Orchestration (coordination)
3 Latency and failure from dependencies
4 Availability
5 Security
6 Database
Event-Sourcing
CQRS
Distributed transaction
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 8 / 24
Microservices in action Overcome disadvantages
Overcome disadvantages
Determine “Bounded Context”
Deployability, testability and management - service discovery and
coordinator
Performance - latency and failure from dependencies
Availability - cluster or HA for dynamic discovery servers
Security between components
Database (most difficult and most important) - event source, CQRS,
long-lived transaction
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 9 / 24
Microservices in action 1 Bounded Context
Determine Bounded Context
How do we do?
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 10 / 24
Microservices in action 2 Service discovery and Orchestration (coordination)
Service discovery and Orchestration (coordination)
Service discovery is the automatic detection of devices and services offered
by these devices on a computer network.
Orchestration is the automated arrangement, coordination, and
management of computer systems, middleware, and services
Supported and usually used tools:
Apache ZooKeeper
Consul IO by HashiCorp
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 11 / 24
Microservices in action 3 Latency and failure from dependencies
Latency and failure from dependencies
Review Netflix Histrix:
Give protection from and control over latency and failure from
dependencies accessed (typically over the network) via third-party
client libraries.
Stop cascading failures in a complex distributed system.
Fail fast and rapidly recover
Fallback and gracefully degrade when possible
Enable near real-time monitoring, alerting, and operational control
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 12 / 24
Microservices in action 3 Latency and failure from dependencies
Review Netflix Histrix - Circuit breaker
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 13 / 24
Microservices in action 4 Availability
Availability
Deploy cluster of Apache ZooKeeper or Consul:
ZooKeeper cluster
Consul cluster
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 14 / 24
Microservices in action 5 Security
Security
Usually using authentication and authorization servers:
Kerberos
Your own JWT system
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 15 / 24
Microservices in action 6 Database
Database - the most important and most difficult
Review three approaches:
Event-Sourcing
CQRS
Distributed transaction
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 16 / 24
Microservices in action 6 Database
Event-Sourcing
Characteristics:
all changes to application state are stored as a sequence of events
all events are immutable
use the events log to reconstruct past states
enable Reactive pattern
Supported tools: Apache Kafka, Akka actor, . . .
More detail: Event-Sourcing Pattern
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 17 / 24
Microservices in action 6 Database
Command-Query Responsibility Segregation (CQRS)
Characteristics:
separate the read and write by using commands and queries
performing modifications and querying data separately
command and query parts could live in different services, or on
different hardware, and could make use of radically different types of
data store
often used in conjunction with the Event-Sourcing pattern
More detail: CQRS Pattern
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 18 / 24
Microservices in action 6 Database
Distributed transaction
Two-phase commit protocol
Long-lived transaction (SAGAS)
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 19 / 24
Microservices in action 6 Database
Two-phase commit protocol
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 20 / 24
Microservices in action 6 Database
Long-lived transaction (SAGAS)
Characteristics from Wikipedia:
a transaction that spans multiple database transactions. Transaction
T can be viewed as a collection of sub-transactions T1, T2, . . ., Tn
a sequence of database transactions grouped to achieve a single
atomic result
support backward and forward recovery. When a failure interrupts,
there are two choices: compensate for the executed transactions
(backward recovery), or execute the missing transactions (forward
recovery)
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 21 / 24
Conclusion
Should we prefer microservices over monolithic?
“Microservices architecture shows a lot of advantages”
However, it is not a silver bullet.
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 22 / 24
References
References
Microservice Architecture
Reactive Microservices Architecture
Pros and Cos
Event-Sourcing
Event-Sourcing CQRS stream processing with Apache Kafka
Akka Persistence
Two-Phase commit protocol
Long-lived transaction - SAGAS
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 23 / 24
Questions and answers
Questions and answers
Thank you for your attention!!!
loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 24 / 24

Microservices vs monolithic

  • 1.
    Microservices - Comparingwith monolithic architecture The good, the Bad and the Ugly Xuan-Loi Vu Vega’s Tech Department 98 Hoang Quoc Viet Hanoi, 06 - 01 - 2017 loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 1 / 24
  • 2.
    Introduction Table of Contents 1Introduction Monolithic architecture Microservices architecture 2 Microservices in action 1 Bounded Context 2 Service discovery and Orchestration (coordination) 3 Latency and failure from dependencies 4 Availability 5 Security 6 Database Event-Sourcing CQRS Distributed transaction loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 2 / 24
  • 3.
    Introduction Monolithic and Microservices loivx@vega.com.vn(Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 3 / 24
  • 4.
    Introduction Monolithic architecture Monolithicarchitecture Characteristics: one code base usually one programming language rarely, one application with more than two databases deploy one WAR file (or directory hierarchy) scale application by running multiple copies using load balancer · · · loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 4 / 24
  • 5.
    Introduction Microservices architecture Microservicesarchitecture Characteristics: multiple code bases full-stack or polygot component’s database is independent easy of deployment and scaling · · · loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 5 / 24
  • 6.
    Introduction Microservices architecture Prosand Cos pros Decentralize application so that easier maintain Re-used component Deployability - agility to roll out new versions Reliability - fault affects that microservice alone and its consumers (bulkhead) Availability - rolling out a new version of a microservice requires little downtime Scalability - can be scaled independently using pools, clusters, grids Modifiability - more flexibility to use new frameworks, libraries, datasources, and other resources Management - application management effort Design autonomy - team has freedom to employ different technologies, frameworks, and patterns loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 6 / 24
  • 7.
    Introduction Microservices architecture Prosand Cos - No silver bullet cos Determine “Bounded Context” Deployability - more complex with many jobs, scripts, transfer areas, and config files Performance - communicate over the network, whereas services within the monolith may benefit from local calls Availability - belongs to dynamic discovery Modifiability - database inconsistency, transaction, . . . Testability - harder to setup and run Management - application operation effort increases because there are more runtime components, log files, and point-to-point interactions to oversee Security loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 7 / 24
  • 8.
    Microservices in action Tableof Contents 1 Introduction Monolithic architecture Microservices architecture 2 Microservices in action 1 Bounded Context 2 Service discovery and Orchestration (coordination) 3 Latency and failure from dependencies 4 Availability 5 Security 6 Database Event-Sourcing CQRS Distributed transaction loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 8 / 24
  • 9.
    Microservices in actionOvercome disadvantages Overcome disadvantages Determine “Bounded Context” Deployability, testability and management - service discovery and coordinator Performance - latency and failure from dependencies Availability - cluster or HA for dynamic discovery servers Security between components Database (most difficult and most important) - event source, CQRS, long-lived transaction loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 9 / 24
  • 10.
    Microservices in action1 Bounded Context Determine Bounded Context How do we do? loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 10 / 24
  • 11.
    Microservices in action2 Service discovery and Orchestration (coordination) Service discovery and Orchestration (coordination) Service discovery is the automatic detection of devices and services offered by these devices on a computer network. Orchestration is the automated arrangement, coordination, and management of computer systems, middleware, and services Supported and usually used tools: Apache ZooKeeper Consul IO by HashiCorp loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 11 / 24
  • 12.
    Microservices in action3 Latency and failure from dependencies Latency and failure from dependencies Review Netflix Histrix: Give protection from and control over latency and failure from dependencies accessed (typically over the network) via third-party client libraries. Stop cascading failures in a complex distributed system. Fail fast and rapidly recover Fallback and gracefully degrade when possible Enable near real-time monitoring, alerting, and operational control loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 12 / 24
  • 13.
    Microservices in action3 Latency and failure from dependencies Review Netflix Histrix - Circuit breaker loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 13 / 24
  • 14.
    Microservices in action4 Availability Availability Deploy cluster of Apache ZooKeeper or Consul: ZooKeeper cluster Consul cluster loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 14 / 24
  • 15.
    Microservices in action5 Security Security Usually using authentication and authorization servers: Kerberos Your own JWT system loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 15 / 24
  • 16.
    Microservices in action6 Database Database - the most important and most difficult Review three approaches: Event-Sourcing CQRS Distributed transaction loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 16 / 24
  • 17.
    Microservices in action6 Database Event-Sourcing Characteristics: all changes to application state are stored as a sequence of events all events are immutable use the events log to reconstruct past states enable Reactive pattern Supported tools: Apache Kafka, Akka actor, . . . More detail: Event-Sourcing Pattern loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 17 / 24
  • 18.
    Microservices in action6 Database Command-Query Responsibility Segregation (CQRS) Characteristics: separate the read and write by using commands and queries performing modifications and querying data separately command and query parts could live in different services, or on different hardware, and could make use of radically different types of data store often used in conjunction with the Event-Sourcing pattern More detail: CQRS Pattern loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 18 / 24
  • 19.
    Microservices in action6 Database Distributed transaction Two-phase commit protocol Long-lived transaction (SAGAS) loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 19 / 24
  • 20.
    Microservices in action6 Database Two-phase commit protocol loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 20 / 24
  • 21.
    Microservices in action6 Database Long-lived transaction (SAGAS) Characteristics from Wikipedia: a transaction that spans multiple database transactions. Transaction T can be viewed as a collection of sub-transactions T1, T2, . . ., Tn a sequence of database transactions grouped to achieve a single atomic result support backward and forward recovery. When a failure interrupts, there are two choices: compensate for the executed transactions (backward recovery), or execute the missing transactions (forward recovery) loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 21 / 24
  • 22.
    Conclusion Should we prefermicroservices over monolithic? “Microservices architecture shows a lot of advantages” However, it is not a silver bullet. loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 22 / 24
  • 23.
    References References Microservice Architecture Reactive MicroservicesArchitecture Pros and Cos Event-Sourcing Event-Sourcing CQRS stream processing with Apache Kafka Akka Persistence Two-Phase commit protocol Long-lived transaction - SAGAS loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 23 / 24
  • 24.
    Questions and answers Questionsand answers Thank you for your attention!!! loivx@vega.com.vn (Tech Department) Microservices Comparing With Monolithic Hanoi, 06 - 01 - 2017 24 / 24