application caching: the hidden microservice

59
Application Caching: The Hidden Microservice Scott Mansfield Senior Software Engineer EVCache

Upload: scott-mansfield

Post on 13-Apr-2017

629 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Application Caching: The Hidden Microservice

Application Caching:The Hidden Microservice

Scott MansfieldSenior Software EngineerEVCache

Page 2: Application Caching: The Hidden Microservice
Page 3: Application Caching: The Hidden Microservice
Page 4: Application Caching: The Hidden Microservice
Page 5: Application Caching: The Hidden Microservice
Page 6: Application Caching: The Hidden Microservice
Page 7: Application Caching: The Hidden Microservice
Page 8: Application Caching: The Hidden Microservice
Page 9: Application Caching: The Hidden Microservice
Page 10: Application Caching: The Hidden Microservice
Page 11: Application Caching: The Hidden Microservice
Page 12: Application Caching: The Hidden Microservice
Page 13: Application Caching: The Hidden Microservice
Page 14: Application Caching: The Hidden Microservice
Page 15: Application Caching: The Hidden Microservice
Page 16: Application Caching: The Hidden Microservice
Page 17: Application Caching: The Hidden Microservice
Page 18: Application Caching: The Hidden Microservice

90 seconds

Page 19: Application Caching: The Hidden Microservice

What do caches touch?

Signing up*Logging inChoosing a profilePicking liked videosPersonalization*Loading home page*Scrolling home page*A/B testsVideo image selection

Searching*Viewing title detailsPlaying a title*Subtitle / language prefsRating a titleMy ListVideo history*UI stringsVideo production*

* multiple caches involved

Page 20: Application Caching: The Hidden Microservice

Home PageRequest

Page 21: Application Caching: The Hidden Microservice
Page 22: Application Caching: The Hidden Microservice

KV store optimized for AWS and tuned for Netflix use cases.

Ephemeral Volatile Cache

Page 23: Application Caching: The Hidden Microservice

What is EVCache?

Distributed, sharded, replicated key-value storeBased on MemcachedTunable in-region and global replicationResilient to failureTopology awareLinearly scalableSeamless deployments

Page 24: Application Caching: The Hidden Microservice

Why Optimize for AWS

Instances disappearZones failRegions become unstableNetwork is lossyCustomer requests bounce between regions

Failures happen, and we test all the time

Page 25: Application Caching: The Hidden Microservice

EVCache Use @ Netflix Hundreds of terabytes of dataTrillions of ops / dayTens of billions of items storedTens of millions of ops / secMillions of replications / secThousands of serversHundreds of instances per clusterHundreds of microservice clientsTens of distinct clusters3 regions4 engineers

Page 26: Application Caching: The Hidden Microservice

Architecture

Server

Memcached

Prana (Sidecar)

Application

Client Library

Client

Eureka(Service Discovery)

Page 27: Application Caching: The Hidden Microservice

Architecture

Page 28: Application Caching: The Hidden Microservice

Reading

Primary Secondary

Page 29: Application Caching: The Hidden Microservice

Writing

Page 30: Application Caching: The Hidden Microservice

Use Case: Lookaside Cache

Application

Client Library

Client Ribbon Client

S S S S

C C C CData Flow

Page 31: Application Caching: The Hidden Microservice

Use Case: Transient Data Store

Application

Client Library

Client

Application

Client Library

Client

Application

Client Library

Client

Time

Page 32: Application Caching: The Hidden Microservice

Use Case: Primary Store

Offline / Nearline Precomputes for

Recommendations

Online Services

Offline Services

Online Application

Client Library

Client

Data Flow

Page 33: Application Caching: The Hidden Microservice

Use Case: High Volume && High Availability

Compute & Publish on schedule

Data Flow

Application

Client Library

Client Ribbon ClientIn-memory Cache

Optional

S S S S

C C C C

Page 34: Application Caching: The Hidden Microservice

Pipeline of Personalization

Compute A

Compute B Compute C

Compute D

Online Services

Offline Services

Compute E

Data Flow

Online 1 Online 2

Page 35: Application Caching: The Hidden Microservice

Polyglot Clients

APP

Java Client

APP

Prana

Local Proxy

Memcached

APP

Memcached Proxy

HTTP

APP

HTTP Proxy

Page 36: Application Caching: The Hidden Microservice

Additional Features

Global data replicationCache warmingSecondary indexingConsistency checking

All powered by metadata flowing through Kafka

Page 37: Application Caching: The Hidden Microservice

Region BRegion A

APP APP

Repl Proxy

Repl Relay

1 mutate

2 send metadata

3 poll msg

5 https s

end msg

6 mutate4 get data

for set

Kafka Repl Relay Kafka

Repl Proxy

Cross-Region Replication

7 read

Page 38: Application Caching: The Hidden Microservice

Cache Warming

Cache Warmer

Kafka

Application

Client Library

Client

Page 39: Application Caching: The Hidden Microservice

Code

Page 40: Application Caching: The Hidden Microservice

Moneta

Next-generationEVCache server

Page 41: Application Caching: The Hidden Microservice

Moneta

Moneta: The Goddess of MemoryJuno Moneta: The Protectress of Funds for Juno

● Evolution of the EVCache server● EVCache on SSD● Cost optimization● Ongoing lower EVCache cost per stream● Takes advantage of global request patterns

Page 42: Application Caching: The Hidden Microservice

Old Server

● Stock Memcached and Prana (Netflix sidecar)● All data stored in RAM in Memcached● Expensive with global expansion / N+1 architecture

external

Page 43: Application Caching: The Hidden Microservice

Optimization

● Global data means many copies● Access patterns are heavily region-oriented● In one region:

○ Hot data is used often○ Cold data is almost never touched

● Keep hot data in RAM, cold data on SSD● Size RAM for working set, SSD for overall dataset

Page 44: Application Caching: The Hidden Microservice

New Server

● Adds Rend and Mnemonic● Still looks like Memcached● Unlocks cost-efficient storage & server-side intelligence

external internal

Page 45: Application Caching: The Hidden Microservice

Rend

Page 46: Application Caching: The Hidden Microservice

Rend

● High-performance Memcached proxy & server● Written in Go

○ Powerful concurrency primitives○ Productive and fast

● Manages the L1/L2 relationship● Tens of thousands of connections

Page 47: Application Caching: The Hidden Microservice

Rend

● Modular to allow future changes / expansion of scope○ Set of libraries and a default

● Manages connections, request orchestration, and communication

● Low-overhead metrics library● Multiple orchestrators● Parallel locking for data integrity

Page 48: Application Caching: The Hidden Microservice

Mnemonic

Open source soon™

Page 49: Application Caching: The Hidden Microservice

Mnemonic

● Manages data storage on SSD● Reuses Rend server libraries● Maps Memcached ops to RocksDB ops

Page 50: Application Caching: The Hidden Microservice

Why RocksDB?

● Fast at medium to high write load○ Goal was 99% read latency below 20ms

● Log-Structured Merge minimizes random writes to SSD○ Writes are buffered in memory

● Immutable Static Sorted Tables

. . .

Page 51: Application Caching: The Hidden Microservice

How we use RocksDB

● FIFO "Compaction"○ More suitable for our precompute use cases

● Bloom filters and indices pinned in memory○ Trade L1 space for faster L2

● Records sharded across many RocksDBs per instance○ Reduces number of files checked, decreasing latency

R...

Key: ABCKey: XYZ

R R R

Page 52: Application Caching: The Hidden Microservice

FIFO Limitation

● FIFO compaction not suitable for all use cases○ Very frequently updated records may push out valid records

● Future: custom compaction or level compaction

SST

time

SSTSST

Page 53: Application Caching: The Hidden Microservice

Moneta in Production

● Serving all of our personalization data● Rend runs with two ports:

○ One for standard users (read heavy or active data management)○ Another for async and batch users: Replication and Precompute

● Maintains working set in RAM● Optimized for precomputes

○ Smartly replaces data in L1

external internal

Page 54: Application Caching: The Hidden Microservice

Get: 229 μs (139 μs) avgPercentiles:● 50th: 140 μs (113 μs)● 75th: 199 μs (139 μs)● 90th: 318 μs (195 μs)● 95th: 486 μs (231 μs)● 99th: 1.67 ms (508 μs)● 99.9th: 9.68 ms (1.97 ms)

Moneta Performance in Production

Set: 367 μs (200 μs) avgPercentiles:● 50th: 227 μs (172 μs)● 75th: 301 μs (202 μs)● 90th: 411 μs (243 μs)● 95th: 579 μs (295 μs)● 99th: 3.25 ms (502 μs)● 99.9th: 18.5 ms (4.73 ms)

Latencies: peak (trough)

Page 55: Application Caching: The Hidden Microservice

70%Reduction in cost*

70%

Page 57: Application Caching: The Hidden Microservice

Thank You

@[email protected]

Page 58: Application Caching: The Hidden Microservice
Page 59: Application Caching: The Hidden Microservice

Failure Resilience in Client

● Operation Fast Failure● Tunable Retries● Operation Queues● Tunable Latch for Mutations● Async Replication through Kafka