Demolishing Monolith
Getting Started with Microservices
www.mfranc.com
@francmichal
WIFI
PGS Guest
pgswelcome
www.mfranc.com
Michal Franc
Lead Engineer @ Just Eat
Wroclaw <3
SPEAKER
ENGINEER
LEADER
SLACK SPAMMER
- 5 mln users
- 4.5 bln gbp raised
- acquired last week (95 mln gbp)
- 20 mln active users
- 5 bln gbp valuation
- In the top 10 eu unicorns
- 1200+ ec2 instances on prod
- 3200+ on all envs
- microservice event based architecture
- monolith -> microservices
- self server -> cloud
- 300+ ec2 instances
Workshop Goals
-
explore 'microservices'
-
practical monolith -> distributed
-
distributed data
-
pros / cons
-
scalability / availability
-
any other expectations?
-
50 min / section
-
10 min breaks
Agenda
-
Why microservices
-
First microservice
-
Introduction to Monolith
-
Evolution to microservice based architecture
-
QA / Discussion
Preparation
-
git clone git@github.com:mfranc-workshop/wroclaw-pgs-08072017.git
-
docker pull
-
microsoft/dotnet
-
unix - rabbitmq:3-management
-
win - micdenny/rabbitmq-windows
-
-
httpie
-
windows - https://goo.gl/berTLb
-
unix - https://httpie.org/#installation
-
- slack
- devwarsztaty.octal.pl - kanal #29-mikroserwisy
Lets go!
Microservices are on the rise
SOA
Microservices
Microsevices are not the silver bullet
SOA was not the silver bullet
https://setandbma.files.wordpress.com/2012/05/technology-adoption.png
here
Microservices
Why?
MicroService?
Specific Business Goal
Bounded Context
Microservice
Simple Microservice
Demo
Micro Service
Architecture
Monolithic app
https://www.nginx.com/blog/introduction-to-microservices/
https://www.nginx.com/blog/introduction-to-microservices/
Monolithic Shop
Introduction
-
SimpleInjector
-
Quartz
-
EntityFramework
Run and pray!
- dotnet ef migrations add Init
- dotnet ef database update Init
- dotnet restore
- dotnet run <portnumber>
- /initdb
Functional Decomposition
Functional Decomposition
Email Service
Demo-Service
dotnet new micro-basic --name micro-email -o micro-email
http POST localhost:5000/email emailAddress=lam.michal.franc@gmail.com message=test -v
Communication
Http
Demo-Monolith
- dotnet add package RestEase
- Changing to call the emailService
RabbitMQ
RabbitMQ
Preparation
-
RabbitMQ
-
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
-
test -> http://localhost:15672/ | guest / guest
-
Demo-Publisher
- dotnet add package RawRabbit
- dotnet add package RawRabbit.vNext
- dotnet add package Newtonsoft.Json
http://localhost:15672
Exchange
Consuming Messages
- dotnet add package RawRabbit
- dotnet add package RawRabbit.vNext
- dotnet add package Newtonsoft.Json
EmailService
Demo-subscriber
Database as Integration Layer
Database as Integration Layer
-
easy
-
not complex
-
solves a lot of problems
-
good for transitional period
Consume Message
Produce Message
<Check Transfer>
<Transfer Received>
Demo Time
monolithic-producer
payment-controller
Demo Time
microservice-consumer
dotnet new -i micro-job-rabbit
dotnet new micro-job-rabbit -o micro-transfer --name micro-transfer
'Private' Data Snapshot
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.EntityFrameworkCore.Sqlite
<ItemGroup> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" /> </ItemGroup>
dotnet add package Microsoft.EntityFrameworkCore.Sqlite
- consume message
- persist order Id in DB
- run job checking the DB
- produce message of order transfer is finished
Database per service?
Distributed Data
Bounded Context Isolation
How to update Order now?
Payments
&
Warehouse
Simple CQRS
Where is the Master Database?
Read Model
Master
DB
Replay
Messages
Rebuilding Read Model
Master
DB
Read Model
Read
Model
Where is the Master Database?
Read Model
Event
Store
EventsSourcing
Domain Events
OrderTransferFinished
Commands vs Events
UpdateOrder vs OrderStatusChanged
Time For Docker
docker build
docker build -t workshop/micro-mail .
docker build -t workshop/micro-shop .
docker build -t workshop/micro-transfer .
docker ps -a docker history docker images docker stop / start docker check logs docker exec -it
docker run --name micro-email -d -p 5001:5001 workshop/micro-email 5001
docker run --link micro-email:email -d -p 5000:5000 --name micro-shop workshop/micro-shop 500
Scaling
Registry & Management
And more and more stuff ...
Conclusion
Q/A
Discussion
AMA
Micro Workshop main
By Michal Franc
Micro Workshop main
- 1,295