Creating microservices
architectures using node.js and
Kubernetes
CTO at seedtag
Paul Goldbaum
Who is this guy?!
@paulgoldbaum
Our original stack
Symfony 2
MongoDB
Physical servers hosted at OVH
PHP 5.6
Our current stack
MongoDB + Google Datastore
Kubernetes through Google Container Engine
Node.js + Express
Apache Spark
Don’t do it*
Why do we need a
microservices platform?
Platform
Load Balancer
Deployment manager
Log handler
Process supervisor
Service discovery
Service communication
Storage manager
Abstract away differences between services
Isolate apps from each other
Reserve resources in shared execution environment
Wrap as executable unit
Provides deployment, scaling and management of
containerized applications
Works on some of the main public and private cloud providers
and on-premise
Serves as a layer of abstraction over the infrastructure
Container cluster manager built by Google after Borg
Putting services into
production
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.send('Hello World!');
})
app.listen(3000, function() {
console.log('Application running on port 3000!');
})
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: hello-world
spec:
replicas: 2
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: main
image: hello-world:v1
kubectl create -f hello-world.yaml
kubectl set image deployment/hello-world main=hello-world:v2
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
})
app.get('/status', function (req, res) {
res.sendStatus(200);
})
app.listen(3000, function() {
console.log('Application running on port 3000!');
})
…
spec:
containers:
- name: hello-world
image: hello-world:v1
ports:
- containerPort: 3000
readinessProbe:
httpGet:
path: /status
port: 3000
periodSeconds: 5
Service B
…
var ready = true;
app.get('/status', function (req, res) {
if (ready) { res.sendStatus(200); }
else { res.sendStatus(500); }
})
process.on('SIGTERM', function () {
ready = false;
setTimeout(function() {
server.close(function () {
process.exit(0);
});
}, 10000);
});
…
Choosing
programming languages
Small services give us
flexibility when choosing
languages/frameworks
We can now use right tool
for the right job
but…
status endpoint / connection drain
docker build
test environment
app instrumentation
Custom NodeJS
Microservices Framework
… now what?
Creating a new microservice should be EASY
Communicating
microservices
GET /users HTTP/1.1
App A App B
?
Synchronous
communication
Synchronous communication using
Kubernetes services
App A Service B
App B
App B
App B
apiVersion: v1
kind: Service
metadata:
name: hello-world
spec:
ports:
- port: 3000
targetPort: 3000
selector:
app: hello-world
Synchronous communication using
Kubernetes services
App A Service B
App B
App B
App B
Synchronous communication using
Kubernetes services
App A Service B
App B
App B
App B
Circuit
Breaker
App A
App B
Message bus
OMG
LOL
Asynchronous communication
Monitoring
services
Prometheus
Labels can be added to time series to allow grouping
of data by any criteria
Provides powerful query operators
Allows to use queries to generate alerts
Time-series database created by SoundCloud
ALERT my_request_rate
IF sum(rate(http_requests_total{kubernetes_name=“hello-world”}[1m])) < 100
FOR 5m
LABELS {
severity = "urgent"
}
Connects to many different backend such as
Prometheus, Graphite, InfluxDB, Elasticsearch, …
Great for having your stats up on a screen in the office
Web-based dashboard creator for visualizing time-series
and application metrics
kube-state-metrics
node-exporter
Feeding data into our system
express-prom-bundle
Service A
Service B
Service C
Instrumented apps send spans to Zipkin
Outgoing requests are marked with a
correlation ID
Zipkin joins spans from a single correlation
ID together to form traces
Distributed tracing system by Twitter
Measure everything!
Microservices are hard, imply a lot more operations work
Creating a custom microservices framework is key to agility
Conclusions
careers@seedtag.com
Do you want to help us change the world of online advertising. Join us!
Thank you!
Contact: paul.goldbaum@gmail.com - @paulgoldbaum

Creating microservices architectures using node.js and Kubernetes