Microservices

How do I scale my codebase?

Microservices

A way of structuring your codebase to allow easy extensibility, higher maintainability and code collaboration.

The monolithic way

Separation of concerns

Divide your codebase in sections, such that each section is responsible for one and only thing.

Instead we do this

Magento

and this

https://goo.gl/1Nbxos (Bill Scott keynote)

MAINTAINABILITY

Think of the 80/20 Rule (The Pareto Law)

80% of your bugs are residing inside the 20% percent of your code. 

NOW FIND THAT 20% INSIDE MILLIONS OF LOC.

Version control - conflicts

  • How much time do you spend resolving conflicts?
  • Do you dare to go back in history in search of a commit?

Scalability

  • Monolithic Applications scale by adding more instances/servers/resources.
  • But how much of those can you add?
  • Are the resources used efficiently?

Extensibility

  • Unless you have a test suite with 100% test coverage, you don't change things.
  • Instead you add and add and keep adding.
  • Monolithic apps are keep getting larger.

The monolithic way

One code base to rule em all.

  • Maintainability
  • Code collaboration
  • Conflicts/Merges
  • SoC
  • Scalability/Extensiblity

Enter the new World Order

Microservices Architecture

  • Easier to maintain
  • Multiple teams work on multiple services
  • Fewer conflicts
  • Different stacks work for the same purpose
  • SoC
  • Easy to scale/extend, Just add a service

let's build an e-shop

Your app has/needs

  • Persistent storage

  • UI / Mobile App

  • Lots of Business Logic

Choose your intercommunication

  • Task Queue

  • REST APIs

Isolate the Database

  1. Put a REST API in front of your Database

  2. Let every other service that needs persistent storage to talk to the Data API

  3. Reflect your Business Logic in your API endpoints

Create a Newsletter Service

  • Sends Emails, talks to Sendmail, Gunmail, etc

  • Keeps tracks of templates sent, analytics, etc

  • Utilizes the Data API

Create the UI Service

  • Will contain HTML, CSS, Client Side Business Logic, etc

  • Reads / Writes the Data API

Create the Mobile App

  • Will contain Native language stuff

  • Reads / Writes the Data API

What else do you need? Just create a service

Learn from the experts

  • Twitter
  • Netflix

Werner Vogels

If you hit the Amazon.com gateway page, the application calls more than 100 services to collect data and construct the page for you.

 

http://goo.gl/92xpfk

CTO/VP @ Amazon

If you start with Microservices, you are starting wrong.

Martin Fowler

Thank you

Microservices

By Kostas Bariotis