How Mapbox Scales over 9 AWS Regions

56
How Mapbox Scales Over 9 Data Centers Johan @freenerd [email protected] Madrid DevOps November 2015 1

Transcript of How Mapbox Scales over 9 AWS Regions

Page 1: How Mapbox Scales over 9 AWS Regions

How Mapbox ScalesOver 9 Data Centers

Johan@[email protected] DevOps November 2015

1

Page 2: How Mapbox Scales over 9 AWS Regions

• What is Mapbox?

• 9 data centers?

• Tracing a map request

2

Page 3: How Mapbox Scales over 9 AWS Regions

3

Page 4: How Mapbox Scales over 9 AWS Regions

4

Page 5: How Mapbox Scales over 9 AWS Regions

5

Page 6: How Mapbox Scales over 9 AWS Regions

6

Page 7: How Mapbox Scales over 9 AWS Regions

• What is Mapbox?

• 9 Data Centers?

• Tracing a map request

7

Page 8: How Mapbox Scales over 9 AWS Regions

9 Data Centers?

8

Page 9: How Mapbox Scales over 9 AWS Regions

9

Page 10: How Mapbox Scales over 9 AWS Regions

10

Page 11: How Mapbox Scales over 9 AWS Regions

9 Data Centers?

• Why run this in many regions?

• One region = cheaper, less complex, easier to build and maintain

11

Page 12: How Mapbox Scales over 9 AWS Regions

9 Data Centers?

• Global high availability

• Global low latency

12

Page 13: How Mapbox Scales over 9 AWS Regions

9 Data Centers?Global high availability

13

Page 14: How Mapbox Scales over 9 AWS Regions

9 Data Centers?Global high availability

• Mapbox is critical infrastructure for our customers

• Mapbox SLA: 99.9%

• Problems for high availability

• AWS problems

• Mapbox software or configuration problems

• Critical deploys14

Page 15: How Mapbox Scales over 9 AWS Regions

9 Data Centers?

• Global high availability

• Global low latency

15

Page 16: How Mapbox Scales over 9 AWS Regions

9 Data Centers?Global low latency

16

Page 17: How Mapbox Scales over 9 AWS Regions

9 Data Centers?Global low latency

• Can't beat the speed of light

• Latency is critical for using a map

• Bring our data closer to our users

17

Page 18: How Mapbox Scales over 9 AWS Regions

9 Data Centers?

• Global high availability

• Global low latency

18

Page 19: How Mapbox Scales over 9 AWS Regions

Let's trace a request

19

Page 20: How Mapbox Scales over 9 AWS Regions

20

Page 21: How Mapbox Scales over 9 AWS Regions

21

Page 22: How Mapbox Scales over 9 AWS Regions

What is a map?

22

Page 23: How Mapbox Scales over 9 AWS Regions

23

Page 24: How Mapbox Scales over 9 AWS Regions

• Grid over the world

• Every cell of the grid is a tile• Different zoomlevels

• Zoomlevel 0 is the world

• Zoomlevel 13 is a city

• Every tile is identified by mapid, coordinates and zoomlevel

24

Page 25: How Mapbox Scales over 9 AWS Regions

25

Page 26: How Mapbox Scales over 9 AWS Regions

Client• Browser loads Javascript

• Mapbox.js allows for customizing map with very few lines

• Javascript

• Determine viewport

• Request each individual tile

26

Page 27: How Mapbox Scales over 9 AWS Regions

Client

https://tiles.mapbox.com/v4/map.id/17/70428/42997.png?access_token=pk.xxx

27

Page 28: How Mapbox Scales over 9 AWS Regions

28

Page 29: How Mapbox Scales over 9 AWS Regions

CDN• Content Distribution Network

• Physical cache close to users

• AWS: Cloudfront

• Others: Akamai, Fastly, CloudFlare

29

Page 30: How Mapbox Scales over 9 AWS Regions

CDN

30

Page 31: How Mapbox Scales over 9 AWS Regions

CDN• When a request comes in:

• Find nearest edge location

• Terminate TLS

• Match request to behaviour

• Look in cache (based on URL & Query String)

• If object is there: return

31

Page 32: How Mapbox Scales over 9 AWS Regions

CDN• Your CDN works best if it can serve everything from cache

• How to remove stale data?

• Trade-off: high cache hit rate vs. update delay

• Time-To-Live when a cached object expires

• We use 5 minutes

• 35 % cache hit rate

32

Page 33: How Mapbox Scales over 9 AWS Regions

33

Page 34: How Mapbox Scales over 9 AWS Regions

DNS• Originally: Resolve domain names to IP addresses

• Also: Route request to nearest data center

• best region for request based historic on latency

• Amazon: Route53

• Others: Dyn, easyDNS, Akamai34

Page 35: How Mapbox Scales over 9 AWS Regions

DNS

35

Page 36: How Mapbox Scales over 9 AWS Regions

36

Page 37: How Mapbox Scales over 9 AWS Regions

Load Balancer• Route requests to application servers

• Entry point to a region

• AWS: Elastic Load Balancer (ELB)

• Others: haproxy, nginx, f5

37

Page 38: How Mapbox Scales over 9 AWS Regions

Load Balancer• Terminate TLS

• Determine which application server to route to

• Healthy server

• ELB: Server with least outstanding requests

• Wait for results and return

38

Page 39: How Mapbox Scales over 9 AWS Regions

39

Page 40: How Mapbox Scales over 9 AWS Regions

Application Servers• Virtual Machines

• AWS: Elastic Compute Cloud (EC2)

• Others: Google Compute Cloud, Rackspace, Digital Ocean

40

Page 41: How Mapbox Scales over 9 AWS Regions

Application Servers• c3.xlarge instances

• Ubuntu Linux

• Node.js/Express

41

Page 42: How Mapbox Scales over 9 AWS Regions

Application Servers• Authenticate

• Load map data

• Fetch tile and return

42

Page 43: How Mapbox Scales over 9 AWS Regions

43

Page 44: How Mapbox Scales over 9 AWS Regions

DynamoDB

• Primary/Replica

• Reads to replicas, writes only to primary

• Replicas only in 2 regions

• Reads for non-replica regions need to go over the Internet

• In-instance caching of authentication/map information

1 https://www.mapbox.com/blog/scaling-the-mapbox-infrastructure-with-dynamodb-streams/

44

Page 45: How Mapbox Scales over 9 AWS Regions

45

Page 46: How Mapbox Scales over 9 AWS Regions

Application ServersFetch tiles

• check simultanously in cache (redis) and object store (s3)

• return from where is found first

• if only found in object store, update local cache

46

Page 47: How Mapbox Scales over 9 AWS Regions

Application Servers• redis is used as least-recently used cache, thus popular tiles

for a region are usually cached

• s3 is slow, because data is in us-east-1 bucket only

• Stats:

• 80% cache hits

• r3.4xlarge with 122 GB of memory

47

Page 48: How Mapbox Scales over 9 AWS Regions

48

Page 49: How Mapbox Scales over 9 AWS Regions

49

Page 50: How Mapbox Scales over 9 AWS Regions

From 2 to 9 regions

50

Page 51: How Mapbox Scales over 9 AWS Regions

From 2 to 9 regions

51

Page 52: How Mapbox Scales over 9 AWS Regions

From 2 to 9 regions

52

Page 53: How Mapbox Scales over 9 AWS Regions

Thanks

• What is Mapbox?

• 9 Data Centers?

• Tracing a Map Request

@[email protected]

53

Page 54: How Mapbox Scales over 9 AWS Regions

http://geodevelopers.org/54

Page 55: How Mapbox Scales over 9 AWS Regions

Elasticity• EC2 instances are provisioned via Auto Scaling Group

• Auto Scaling is based on instance CPU load

• Scale up/down if CPU load over/under 55%/20% for 2 minutes

55

Page 56: How Mapbox Scales over 9 AWS Regions

56