scala - experiences

22
Scala - Experiences Leon Maia @leonmaia CPH Scala Meetup 3.11.16

Upload: leon-maia

Post on 14-Apr-2017

81 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Scala - Experiences

Scala - ExperiencesLeon Maia@leonmaia

CPH Scala Meetup3.11.16

Page 2: Scala - Experiences

About me

● HP, Hotel Urbano, Globo.com and now Tradeshift.● Scala for the last 4 years.● Interests: Distributed Systems, highly available and fault tolerant systems.

2

Page 3: Scala - Experiences

Agenda

● Globo?● Challenges - Goals.● Geofencing - how we solved it?● Finagle - Filters.● Scalaz - Either.● The Extractor Pattern.● Readers.● Rio 2016 Olympics.● Metrics, Metrics, Everywhere.● DEMO.

3

Page 4: Scala - Experiences

Globo?

4

$4.83 billion in media revenue

Page 5: Scala - Experiences

Our stack

● Scala.● Finagle.● Twitter Server.● Guava Cache.● Zipkin.

5

Page 6: Scala - Experiences

Challenges - Goals

● Be able to handle absurd spikes on the API during the beginning of the events.

● Make it super simple to adjust settings live.● ZERO DOWNTIME.

○ HA + FT!

● High-throughput and low-latency!● Non-disruptive background loading.● Geofencing.

6

Page 7: Scala - Experiences

Geofencing

7

Page 8: Scala - Experiences

The geofencing problem

● Geofences extensively used for geo-based transmissions.● MySQL Geometry functions.● 3 decimal places - 110m.● Not able to cache.

8

Page 9: Scala - Experiences

Numbers..?

● The response time was < 5 ms at 95th percentile, and < 50 ms at the 99th percentile.

● Was able to handle 64000 req/s with 7 machines running at 40% CPU usage.

9

Page 10: Scala - Experiences

10

Page 11: Scala - Experiences

Using Either

11

Page 12: Scala - Experiences

Using Either - Part 2

12

Page 13: Scala - Experiences

Filters

13

Page 14: Scala - Experiences

Clients

14

Page 15: Scala - Experiences

The extractor pattern

● Decompose various kinds of data structures using pattern matching.● Constructor: creates an object from a given list of parameters.● Extractor: extracts the parameters from which an object passed to it was

created.

15

Page 16: Scala - Experiences

Besides all that, it must be simple.

16

Page 17: Scala - Experiences

What we achieved

● Good maintainability.● Absurdly low response times.● Robust error handling and recovery.● Smart caching.● Able to handle huge traffic spikes.

17

Page 18: Scala - Experiences

Rio 2016 Olympics.

18

Page 19: Scala - Experiences

19

Audience during the game BRA x SWE.

Page 20: Scala - Experiences

“We used around 5.5 TB of memory with 1056 CPUs across two PoPs located in the southeast of the country.

20

Page 21: Scala - Experiences

DEMO

21

Page 22: Scala - Experiences

Thanks!

22