Experiences with Microservices at Tuenti

84
.Experiences with Microservices at Aarón Fas Andrés Viedma

Transcript of Experiences with Microservices at Tuenti

Page 1: Experiences with Microservices at Tuenti

.Experiences with Microservices at

Aarón FasAndrés Viedma

Page 2: Experiences with Microservices at Tuenti

Microservices?

I know what you’re probably thinking...

Page 3: Experiences with Microservices at Tuenti
Page 4: Experiences with Microservices at Tuenti
Page 5: Experiences with Microservices at Tuenti
Page 6: Experiences with Microservices at Tuenti

Who did you say these guys are?

Andrés Viedma@andres_viedma

Aarón Fas@aaronfc

Javadinosaur

Useless gadgets buyer

Page 7: Experiences with Microservices at Tuenti

About

Page 8: Experiences with Microservices at Tuenti

From Social Network...

Page 9: Experiences with Microservices at Tuenti

From Social Network...

Page 10: Experiences with Microservices at Tuenti

To Mobile Operator(full MVNO)

Page 11: Experiences with Microservices at Tuenti

The PHPMonolith

One single source repository

PHP???

Page 12: Experiences with Microservices at Tuenti

Do you need a release?

Take a ticketand wait...

Page 13: Experiences with Microservices at Tuenti

.Microservices

Page 14: Experiences with Microservices at Tuenti

Microservices… again… (and take a shot)

❖ Distributed, independently deployable components

❖ Well defined interfaces

❖ Simple communication interface (HTTP?)

❖ Each service has its own DB

❖ Each service has its own source repository

Page 15: Experiences with Microservices at Tuenti

Microservices… again… (and take a shot)

❖ Distributed, independently deployable components

❖ Well defined interfaces

❖ Simple communication interface (HTTP?)

❖ Each service has its own DB

❖ Each service has its own source repository

THAT ISSOA !!!

Page 16: Experiences with Microservices at Tuenti

Microservices… again… (and take a shot)

❖ Distributed, independently deployable components

❖ Well defined interfaces

❖ Simple communication interface (HTTP?)

❖ Each service has its own DB

❖ Each service has its own source repositoryIs that important enough to deserve a new name???

Page 17: Experiences with Microservices at Tuenti

Mixing technologies

❖ Allows using different languages

❖ Different platform versions

❖ Incremental technology changes / evolution

Page 18: Experiences with Microservices at Tuenti

Separation of responsibilities

❖ Forces separation of responsibilities

➢ Subsystems with well defined facades

➢ Different source repositories

Page 19: Experiences with Microservices at Tuenti

Separation of responsibilities

❖ Forces separation of responsibilities

➢ Subsystems with well defined facades

➢ Different source repositories

YOU DON’T NEED MICROSERVICES!

USE JARS !!!

Page 20: Experiences with Microservices at Tuenti

Continuous deployment

«Our highest priority is to satisfy the customerthrough early and continuous deliveryof valuable software.»

«The best architectures, requirements, and designsemerge from self-organizing teams.»

-- Principles of the Agile Manifesto

Page 21: Experiences with Microservices at Tuenti

Continuous deployment

«Our highest priority is to satisfy the customerthrough early and continuous deliveryof valuable software.»

«The best architectures, requirements, and designsemerge from self-organizing teams.»

-- Principles of the Agile Manifesto1 Service => 1 Team?

Better than Continuous delivery!:Continuous deployment

Team responsible of the deployments?

Page 22: Experiences with Microservices at Tuenti

Beware! High costs

❖ No transactions!

➢ Distributed tx?

❖ Requires a much more complex infrastructure

❖ Difficult integration testing

Page 23: Experiences with Microservices at Tuenti

For us: Seemed like a good idea

❖ We have small self-organized teams => Continuous deployment is a reality

❖ We wanted Java, we had PHP

❖ Strong SRE / DevOps team

❖ Our software was intended mainly to access 3rd parties => transactions not possible anyway

Page 24: Experiences with Microservices at Tuenti

.Communications protocol

Page 25: Experiences with Microservices at Tuenti

Existing libraries

❖ No PHP implementation➢ Avro, Etch, Netflix stack

❖ Only serialization➢ Protocol buffers

❖ Didn’t exist or were too new➢ Cap’n Proto, gRPC

❖ Thrift?➢ Good option, but a lot of PHP boilerplate

Page 26: Experiences with Microservices at Tuenti

TService

❖ Own abstraction layer - RPC based❖ Basic implementation: JSON-RPC❖ Interface Definition Language (IDL)❖ Generates Java / PHP / Erlang:

➢ Interchange objects

➢ Client

➢ Server stub

Page 27: Experiences with Microservices at Tuenti

TService IDL/** * Manages the transfer of balance between subscriptions. * @version 1 */interface BalanceTransferService {

/** Transfer money from one subscription to another one. */String transfer(Donation donation) throws NoSuchSubscriptionException;(...)

}

/** Donation between two subscriptions. */class Donation {

/** Id of the donor */long from;/** Amount of money to transfer */int amount;(...)

}

class NoSuchSubscriptionException extends Exception {int code = 100;

}

Java???

Page 28: Experiences with Microservices at Tuenti

TService Versioning

Interface v1

Service

Client 1

Client 2

(compatible changes)

● New methods● New fields in objects

● New parameters in methods

● Delete methods / parameters / fields

Page 29: Experiences with Microservices at Tuenti

TService Versioning

Interface v1

Service

Interface v2

Client 1

Client 2

(compatible changes)

Page 30: Experiences with Microservices at Tuenti

TService Versioning

Interface v1

Service

Interface v2

Client 1

Client 2

(compatible changes)

Page 31: Experiences with Microservices at Tuenti

.Java Platform

Page 32: Experiences with Microservices at Tuenti

Technology stack

Page 33: Experiences with Microservices at Tuenti

XConfig

❖ Own configuration system❖ YAML files based❖ Git repository❖ Overriding system: by env, common / service❖ Hot reloading

➢ Everything adjusts to changes: even DB pools!

➢ No restart required

Page 34: Experiences with Microservices at Tuenti

Async jobs

TService request processing Enqueue

job

Queued jobs

Executor thread pool

Page 35: Experiences with Microservices at Tuenti

Async jobs

TService request processing Enqueue

job

Queued jobs

Executor thread pool

Cron jobs

Cron jobs programming in config

Page 36: Experiences with Microservices at Tuenti

Feature disabling

❖ Activation / deactivation of features by config➢ Is the new development risky?

➢ Is the rest of services / environment ready for the change?

❖ Partial activation of a feature for a % of users➢ Incremental activation of an optional risky change

➢ A / B tests

Page 37: Experiences with Microservices at Tuenti

Integration tests

❖ Custom JUnit runner➢ Bootstraps the platform

➢ Cleans / restarts the local database

➢ Allows the use of @Inject in tests

➢ Allows overriding in dependency injection => inject mocks of the other services

❖ Uses special, “development” XConfig repo

Page 38: Experiences with Microservices at Tuenti

.Monitoring

Page 39: Experiences with Microservices at Tuenti

Monitoring, a priority

❖ What is happening or has happened?➢ Logs

➢ Metrics

➢ Alarms

❖ Distributed architectures are much more difficult to track

Page 40: Experiences with Microservices at Tuenti

And basically because...

Page 41: Experiences with Microservices at Tuenti

.Let’s talk about logs

Page 42: Experiences with Microservices at Tuenti

Logging

❖ Logging library in Java?➢ Log4j

❖ We needed full details➢ Filters to expand/simplify information logged

➢ Multiple appenders logged into distinct storages

Page 43: Experiences with Microservices at Tuenti

❖ Overview of appenders

Logging

log.info(...); Logger

MySQL Appender

LogStash Appender

Hadoop Appender

Page 44: Experiences with Microservices at Tuenti

❖ Following call’s path (TService calls logging)

Logging

ServiceA ServiceB ServiceCGlobalID = 100RequestID = 1

GlobalID = 100RequestID = 2

GlobalID = 100RequestID = 3

Benefits● Locate in/out for calls● Get all interactions

Page 45: Experiences with Microservices at Tuenti

Logging

❖ Kibana dashboard

What does it look like?

Page 46: Experiences with Microservices at Tuenti

Change query

Page 47: Experiences with Microservices at Tuenti

Customize filters

Page 48: Experiences with Microservices at Tuenti

Log types by color

Page 49: Experiences with Microservices at Tuenti

Full log details

Page 50: Experiences with Microservices at Tuenti

.Let’s talk about metrics

Page 51: Experiences with Microservices at Tuenti

Metrics

❖ We graphs➢ As easy as possible to track new metrics

❖ Do not reinvent the wheel➢ Already using StatsD/Graphite on PHP side

❖ What are we tracking?➢ Basic monitoring metrics added by the platform

➢ Metrics from Tomcat JMX

➢ Metrics related to business

Page 52: Experiences with Microservices at Tuenti

Metrics

❖ Multiple graphs dashboards tested➢ Default graphite one

➢ Grafana

Page 53: Experiences with Microservices at Tuenti

Graphite’s is a little ugly...

Page 54: Experiences with Microservices at Tuenti

Grafana is prettier

Page 55: Experiences with Microservices at Tuenti

Layout customized

Page 56: Experiences with Microservices at Tuenti

Much better UI to create graphs

Page 57: Experiences with Microservices at Tuenti

.Let’s talk about alarms

Page 58: Experiences with Microservices at Tuenti

Alarms

❖ Graphs are ok, but we don’t have people 24x7 staring at them.➢ We need notifications

❖ Different things to monitor➢ SQL queries

➢ Graphite metrics

➢ HTTP requests

➢ ...

Page 59: Experiences with Microservices at Tuenti

Alarms

❖ Created our own alarms system➢ Multiple data sources and easily extensible

➢ Quick edition of conditions

➢ Observers for alarms

❖ We ended up using mainly➢ MySQL and Graphite data sources

➢ Java Expression Language on config checkers

➢ Email notifications

Page 60: Experiences with Microservices at Tuenti

… and then, we found Cabot

Separated by service

Page 61: Experiences with Microservices at Tuenti

Cabot overview

Multiple integrations

Page 62: Experiences with Microservices at Tuenti

Cabot overview

Service status overview

Page 63: Experiences with Microservices at Tuenti

Cabot overview

Graphite checks

Page 64: Experiences with Microservices at Tuenti

Cabot overview (Creating new check)

Set graphite metric

Page 65: Experiences with Microservices at Tuenti

Cabot overview (Creating new check)

Check data

Page 66: Experiences with Microservices at Tuenti

Cabot overview (Creating new check)

Set check type/value

Page 67: Experiences with Microservices at Tuenti

Cabot overview (Creating new check)

Set importance

Page 68: Experiences with Microservices at Tuenti

Cabot

❖ Benefits of using Cabot➢ Friendlier UI than config files➢ No dependency on the service monitored➢ Opensource and many integrations

Page 69: Experiences with Microservices at Tuenti

Alarms

❖ Where are we heading now?➢ Moving now most Graphite alarms to Cabot

➢ Replacing thresholds with dynamic expectations (Holt Winters)

❖ It is still the main alarms platform being used

Page 70: Experiences with Microservices at Tuenti

.That’s all about monitoring

Page 71: Experiences with Microservices at Tuenti

.Some Lessons learned

Page 72: Experiences with Microservices at Tuenti
Page 73: Experiences with Microservices at Tuenti

GO ASYNC!!!

Page 74: Experiences with Microservices at Tuenti

Don’t get blocked for too long

❖ Concurrent requests: don’t wait for free threads➢ Own Rate limit mechanism

➢ Tune container thread pool size

➢ Tune database pool (and other possible blocking pools)

❖ Tune clients timeout➢ It may depend on called service / operation

➢ It may depend on the caller

Page 75: Experiences with Microservices at Tuenti

Asynchronous logging

log.info(...)Appender MySQL

Appender Logstash

AppenderHadoop

Logger

Page 76: Experiences with Microservices at Tuenti

Asynchronous logging

log.info(...)

When the ring buffer is full…WAIT!

Appender MySQL

Appender Logstash

AppenderHadoop

Logger

Ring buffer

Async Logger

Not configurable!

Page 77: Experiences with Microservices at Tuenti

Asynchronous logging

log.info(...)

When the ring buffer is full…WAIT!

Appender MySQL

Appender Logstash

AppenderHadoop

Logger

Ring buffer

Async Logger

Async Appender

Async Appender

Async Appender

Not configurable!

When async appender full, messages are discarded

Page 78: Experiences with Microservices at Tuenti

Asynchronous operations

❖ Getters➢ Make them fast (sacrifice consistency)

➢ Cache

➢ Use default values

❖ Setters➢ No operation result

➢ Wait for a notification of operation finished

➢ Query the status of the change

Page 79: Experiences with Microservices at Tuenti

Message queues

❖ Operation queues➢ Retry system

➢ Persistent queues

❖ Publish / subscribe model (pub/sub)➢ Event driven

➢ Reactive programming

Page 80: Experiences with Microservices at Tuenti

Circuit breaker

❖ From the client, consider the status of the service➢ Previous calls

➢ Health checks

❖ If it’s degraded, don’t call it (close the circuit)➢ Return a default response

➢ Enqueue the operation for later retry

➢ Throw an error

Page 81: Experiences with Microservices at Tuenti

.Do It Yourself

Page 82: Experiences with Microservices at Tuenti

Many implementations available

❖ Communication layer➢ gRPC, Cap’n proto, Thrift…

➢ REST, JSON…

❖ Services platform➢ Spring boot, Dropwizard, Spark, Ninja, Jodd…

❖ Netflix stack➢ Hystrix, Ribbon…

Page 83: Experiences with Microservices at Tuenti

Make your own combination!

(it can’t be so difficult…)

Page 84: Experiences with Microservices at Tuenti

Aarón Fas@aaronfc

Andrés Viedma@andres_viedma

.Thanks!Questions?