100% found this document useful (1 vote)
311 views96 pages

Transforming To Microservice

Ichsan walkthrough transitioning from monolith to microservices architecture, briefly discuss about Kubernetes

Uploaded by

Veex Versa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
311 views96 pages

Transforming To Microservice

Ichsan walkthrough transitioning from monolith to microservices architecture, briefly discuss about Kubernetes

Uploaded by

Veex Versa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 96

Deep Dive on Transitioning to

Microservices Architecture

May 2019
Ichsan Rahardianto
Technical Ops Lead at Brankas

[email protected]
https://www.linkedin.com/in/irahardianto/
@irahardianto
Agenda

Background Microservices, how it begins

Team Microservice and agile software development

Tools Technologies and tools to support microservice architecture

K8S Docker & Kubernetes deep dive

Hands On Deploying applications on top of Kubernetes


Background
Microservices
Monolith vs SOA vs Microservices
Monolith vs SOA vs Microservices
Monolith vs SOA vs Microservices
Microservices Challenges
● Distributed computing is hard
● No transactions
○ Multiple databases across multiple services
● Lots of moving parts
● Service discovery
● Increase operation overhead
● Complex infrastructure
Why Transition to
Microservices Then?
Software Delivery in The Past

The Business Dev Ops

Innovation Waterfall Rigorous


Projects Processes
External Vendor Project Delivery

PMO

Software Project A Software Project B Enhancement Project C

Consultant ABC Consultant YXZ Consultant ASD


Project Management
Enter Digital Disruption

World’s Largest World’s Largest Movie World’s Largest Taxi


Accommodation Provider House Owns No Cinema Company Owns No Taxi
Owns No Real Estate
IT is The Business

IT Was Treated As Cost IT Become The Strategic


Center Differentiator

IT Become The Strategic Partner To Business


Continuous Business Value

The Business Dev Ops

Continuous Product Delivery


Internal Product Delivery

Product Management

Product Team A Product Team B Product Team C


The Internet!
source: https://www.internetworldstats.com/emarketing.htm
Scaling Monolith
Vertical Scaling The Mainframe
Mainframe is Costly

Huge Total Cost of Lengthy Procurement Long Time-to-Value


Ownership Processes
Cloud Infrastructure

Time-to-Value Low Total Cost of Scale Any Time, Any Size


Ownership
Horizontal Scaling Microservices in Cloud
Independently Scalable
Cloud Changes How We Treat
Our Infrastructures
Industry Example?
The Death Star Diagram
Amazon is making changes to
production every 11.6 seconds

source: https://www.thoughtworks.com/insights/blog/case-continuous-delivery
Tens of Millions Deployment to All Environment
Team
Product Built by Independent Product Team

Product Team A Product Team B Product Team C Product Team D


Microservices
Oriented
Organization
Independent Product Development Lifecyle

Product Team A Product Team B Product Team C Product Team D


The Team Needs To Be
Loosely Coupled and
Highly Cohesive!
Principle of The Two Pizza Team
Rapid & Continuous Delivery
Partial Update Methods for Rapid Deployment
Technologies & Tools
CI/CD Pipelines
What is Continuous Integration?
What about Continuous Delivery/Deployment?
The Runner
Source Code Analyser
Orchestration and Configuration Management
Fork Based Development (e.g. Open Source Projects)
Branch Based Development (e.g. Gitflow)
Trunk Based Development
TDD & BDD
Unit Test & Integration Test
Test For Your Safety!
Putting All Together

Integration
Test
image: golang:alpine

Example of CI Pipeline yml pipelines:


default:
- step:
script: # Modify the commands below to build your repository.
- PACKAGE_PATH="${GOPATH}/src/bitbucket.org/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}"
- mkdir -pv "${PACKAGE_PATH}"
- apk update && apk add tar jq zip unzip curl python
- tar -cO --exclude-vcs --exclude=bitbucket-pipelines.yml . | tar -xv -C "${PACKAGE_PATH}"
- cd "${PACKAGE_PATH}"
- go get -v
- go build -v
- go test -v
- export IMAGE_NAME=irahardianto/test_ecs:$BITBUCKET_COMMIT
# build the Docker image (this will use the Dockerfile in the root of the repo)
- docker build -t $IMAGE_NAME .
# authenticate with the Docker Hub registry
- docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
# push the new Docker image to the Docker registry
- docker push $IMAGE_NAME
- curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
- unzip awscli-bundle.zip
- ./awscli-bundle/install -b ~/bin/aws
- export PATH=~/bin:$PATH
- $(aws ecr get-login --no-include-email --region ap-southeast-1)
- docker tag $IMAGE_NAME 047415648520.dkr.ecr.ap-southeast-1.amazonaws.com/test_ecs:latest
- docker push 047415648520.dkr.ecr.ap-southeast-1.amazonaws.com/test_ecs:latest
# register the ECS task definition and capture the version
- export TASK_VERSION=$(aws ecs register-task-definition --family test_ecs_dev --container-definitions
"[{\"name\":\"test_ecs_container\",\"image\":\"$IMAGE_NAME\",\"cpu\":1024,\"command\":[\"go\",\"run\",\"testEcs.go\"],\"portMappings\":[{\"containerPort\":8000,\"ho
stPort\":80,\"protocol\":\"tcp\"}],\"memory\":1024,\"essential\":true}]" | jq --raw-output '.taskDefinition.revision')
- echo $TASK_VERSION
- echo "Registered ECS Task Definition:" $TASK_VERSION
# Update the ECS service to use the updated Task version
- aws ecs update-service --cluster ecs-cluster-test --service ecs-cluster-test-service --task-definition test_ecs_dev:$TASK_VERSION

options:
Running Pipeline Example
Kubernetes
Communication
Protocols
Communication via JSON over HTTP
(better known as REST API)
ST
RE PI
A

REST
API

REST
API

T
RES
API

RE PI
ST
A
Communication via gRPC
PC
gR

gRPC

gRPC

C
gRP

gR
PC
What is gRPC
JSON vs Protobuf Contract

service HelloService {
rpc SayHello (HelloRequest) returns (HelloResponse);
}

{ message HelloRequest {
"greeting":"Hello", string greeting = 1;
"name":"John", string name = 2;
"age":32 int32 age = 3;
} }

message HelloResponse {
string reply = 1;
}
gRPC Advantages in Microservices Architecture

Static Type Fast & Efficient Supports


Multi Languages
Handling Request and
Traffic Spike
API Gateway
Circuit Breaker
Avoid Cascading Failure with Circuit Breaker
Implementing
API Gateway
And Circuit-
Breaker
Partial Application
Rollout
Feature Flags/Toggles
A/B Testing
Deep Dive K8S
Kubernetes Architecture in Detail
Pod
Just Enough Docker
Docker vs VM
X86 CPU Ring
Docker Image Size vs VMs

~ 30 MB, Go > 1GB, Any


App Image VM Image
With Smaller Image Size Comes Lots of Advantages

Scaling Out/In Much Faster Easier & Consistent Less Dependencies


< 10 sec Deployment
#
# Nginx Dockerfile
#
# https://github.com/dockerfile/nginx
#

# Pull base image.


FROM dockerfile/ubuntu
Dockerfile Example

# Install Nginx.
RUN \
add-apt-repository -y ppa:nginx/stable && \
apt-get update && \
apt-get install -y nginx && \
rm -rf /var/lib/apt/lists/* && \
echo "\ndaemon off;" >> /etc/nginx/nginx.conf && \
chown -R www-data:www-data /var/lib/nginx

# Define mountable directories.


VOLUME ["/etc/nginx/sites-enabled", "/etc/nginx/certs", "/etc/nginx/conf.d", "/var/log/nginx", "/var/www/html"]

# Define working directory.


WORKDIR /etc/nginx

# Define default command.


CMD ["nginx"]

# Expose ports.
EXPOSE 80
EXPOSE 443
Packing Your App as A Docker Image

# build stage

FROM golang:alpine AS build-env


ADD . /src

RUN cd /src && go build -o goapp

# final stage
FROM alpine

WORKDIR /app
COPY --from=build-env /src/goapp /app/
ENTRYPOINT ./goapp
Pod, Repl Set, Deployment
Services
Cluster IP

This diagram is only to give example, in production you


should use headless service to access database
Node Port
Load Balancer
Volumes
Other Options for Volumes
Think About The Alternative, If We Are Using VMs

Load Balancer
Kubernetes Easily Take 5000 VM for a Single Cluster
Monitoring Using APM
Whats Next?

FaaS / Serverless Chaos Engineering Event-Driven Architecture


/ Lambda
k8s Hands On
Thank You!
Further Readings
https://martinfowler.com/microservices/#what
https://martinfowler.com/bliki/BoundedContext.html
https://martinfowler.com/bliki/CQRS.html
https://www.katacoda.com/
https://www.qwiklabs.com/catalog?keywords=kubernetes
https://github.com/GoogleCloudPlatform/microservices-demo
https://github.com/irahardianto/multitenant-microservices-demo
https://www.oreilly.com/library/view/building-microservices/9781491950340/

You might also like