The Expendables — Backends High Availability at BlaBlaCar

Maxime Fouilleul
Nov 22, 2017 · 13 min read
Image for post
Image for post

Introduction

Infrastructure Ecosystem

Image for post
Image for post
Infrastructure Ecosystem — end of 2017
name: aci.example.com/pod-mysql:10.1-29
pod:
apps:
- dependencies:
- aci.example.com/aci-mariadb:10.1-25
app:
mountPoints:
- {name: mysql-data, path: /var/lib/mysql}
- {name: mysql-log, path: /var/log/mysql}
- dependencies:
- aci.example.com/aci-go-nerve:21-23
- dependencies:
- aci.example.com/aci-prometheus-mysql-exporter:0.10.0-1
[X-Fleet]
MachineMetadata=name=r101-srv1

Service Discovery

Image for post
Image for post
Service Discovery — How does it work ?

Backend High Availability Pillars

Pillar #1 Abolish Slavery

Image for post
Image for post

MySQL at BlaBlaCar

Image for post
Image for post
Synchronous Galera Cluster

Nerve — Track and report service status

# cat env/prod-dc1/services/mysql-main/attributes/nerve.yml
---
override:
nerve:
services:
- name: “main-read"
port: 3306
reporters:
- {type: zookeeper, path: /services/mysql/main_read}
checks:
- type: sql
driver: mysql
datasource: "local_mon:local_mon@tcp(127.0.0.1:3306)/"
- name: "main-write"
port: 3306
reporters:
- {type: zookeeper, path: /services/mysql/main_write}
checks:
- type: sql
driver: mysql
datasource: "local_mon:local_mon@tcp(127.0.0.1:3306)/"
haproxyServerOptions: "backup"
# zookeepercli -c lsr /services/mysql/main_read
mysql-main_read1_192.168.1.2_ba0f1f8b3
mysql-main_read2_192.168.1.3_734d63da
mysql-main_read3_192.168.1.4_dde45787
# zookeepercli -c get /services/mysql/mysql-main_read1_192.168.1.2_ba0f1f8b3
{
"available":true,
"host":"192.168.1.2",
"port":3306,
"name":"mysql-main1",
"weight":255,
"labels":{
"host":"r10-srv4"
}
}
# zookeepercli -c get /services/mysql/mysql-main_write1_192.168.1.2_ba0f1f8b3
{
"available":true,
"host":"192.168.1.2",
"port":3306,
"name":"mysql-main1",
"haproxy_server_options":"backup",
"weight":255,
"labels":{
"host":"r10-srv4"
}
}

Synapse — Service discovery router

# cat env/prod-dc1/services/tripsearch/attributes/synapse.yml
---
override:
synapse:
services:
- name: mysql-main_read
path: /services/mysql/main_read
port: 3307
serverCorrelation:
type: excludeServer
otherServiceName: mysql-main_write
scope: first
- name: mysql-main_write
path: /services/mysql/main_write
port: 3308
serverSort: date
Image for post
Image for post
HaProxy console screenshot
# cat env/prod-dc1/services/tripsearch/attributes/tripsearch.yml
—-
override:
tripsearch:
database:
read:
host: localhaproxy
database: tripsearch
user: tripsearch_rd
port: 3307
write:
host: localhaproxy
database: tripsearch
user: tripsearch_wr
port: 3308

Pillar #2 Be Quiet!

# cat /report_slow_queries.sh#!/dgr/bin/busybox sh
. /dgr/bin/functions.sh
isLevelEnabled "debug" && set -x
slwq=$(/usr/bin/timeout 1 /usr/bin/mysql -h127.0.0.1 -ulocal_mon -plocal_mon information_schema -e "SELECT COUNT(1) FROM processlist WHERE user LIKE '%rd' AND LOWER(command) <> 'sleep' AND time > 1" -BN)if [ $? -eq 0 ] && [ $slwq -eq 0 ]; then
return 0
else
return 1
fi
# cat env/prod-dc1/services/mysql-main/attributes/nerve.yml
---
override:
nerve:
services:
- name: “main-read"
port: 3306
reporters:
- {type: zookeeper, path: /services/mysql/main_read}
checks:
- type: sql
driver: mysql
datasource: "local_mon:local_mon@tcp(127.0.0.1:3306)/"
enableCheckStableCommand: ["/report_slow_queries.sh"]
# bbc mysql prod-dc1 mysql-main mysql-main1 monitor
#1 Weight: 1/255 Processes: 0 Slow: 0
#2 Weight: 2/255 Processes: 0 Slow: 0
#3 Weight: 3/255 Processes: 3 Slow: 0
#4 Weight: 4/255 Processes: 7 Slow: 0
#5 Weight: 6/255 Processes: 10 Slow: 0
#6 Weight: 9/255 Processes: 12 Slow: 0
#7 Weight: 15/255 Processes: 20 Slow: 1 <- SLOW !
#8 Weight: 0/255 Processes: 20 Slow: 1
#9 Weight: 2/255 Processes: 12 Slow: 0
#10 Weight: 3/255 Processes: 4 Slow: 0
#11 Weight: 4/255 Processes: 7 Slow: 0
#12 Weight: 6/255 Processes: 10 Slow: 0
#13 Weight: 9/255 Processes: 12 Slow: 0
#14 Weight: 15/255 Processes: 20 Slow: 0
#15 Weight: 23/255 Processes: 35 Slow: 0
#16 Weight: 38/255 Processes: 40 Slow: 0
#17 Weight: 38/255 Processes: 35 Slow: 0
#18 Weight: 61/255 Processes: 36 Slow: 0
#19 Weight: 61/255 Processes: 47 Slow: 0
#20 Weight: 98/255 Processes: 44 Slow: 0
#21 Weight: 98/255 Processes: 41 Slow: 0
#22 Weight: 158/255 Processes: 38 Slow: 0
#23 Weight: 158/255 Processes: 50 Slow: 0
#24 Weight: 255/255 Processes: 46 Slow: 0 <- FULL POWER !
#25 Weight: 255/255 Processes: 46 Slow: 0

Pillar #3 Die in Peace…

# cat /report_remaining_processes.sh#!/dgr/bin/busybox sh
. /dgr/bin/functions.sh
isLevelEnabled "debug" && set -x
procs=$(/usr/bin/timeout 1 /usr/bin/mysql -h127.0.0.1 -ulocal_mon -plocal_mon information_schema -e "SELECT COUNT(*) FROM processlist WHERE user LIKE '%rd' OR user LIKE '%wr'" -BN)if [ $? -eq 0 ] && [ $procs -eq 0 ]; then
return 0
else
return 1
fi
# cat env/prod-dc1/services/mysql-main/attributes/nerve.yml
---
override:
nerve:
services:
- name: “main-read"
port: 3306
reporters:
- {type: zookeeper, path: /services/mysql/main_read}
checks:
- type: sql
driver: mysql
datasource: "local_mon:local_mon@tcp(127.0.0.1:3306)/"
enableCheckStableCommand: ["/root/report_slow_queries.sh"]
disableGracefullyDoneCommand: ["/root/report_remaining_processes.sh"]

Conclusion

Image for post
Image for post

BlaBlaCar

The stories behind BlaBlaCar, the world’s leading multimodal mobility platform.

Thanks to Olivier Bonnet, Julien Dehee, and Nicola-Marie O'Donovan

Maxime Fouilleul

Written by

Database Engineer at BlaBlaCar / Dad at Life.

BlaBlaCar

BlaBlaCar

BlaBlaCar is the go-to marketplace for shared mobility, combining carpooling, buses and e-scooters. In building the future of mobility, we set ourselves high and ambitious targets, and bring tech and data to the heart of our product experience and company strategy.

Maxime Fouilleul

Written by

Database Engineer at BlaBlaCar / Dad at Life.

BlaBlaCar

BlaBlaCar

BlaBlaCar is the go-to marketplace for shared mobility, combining carpooling, buses and e-scooters. In building the future of mobility, we set ourselves high and ambitious targets, and bring tech and data to the heart of our product experience and company strategy.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store