Slide 1

Slide 1 text

Caching, why not? Highload Meetup: talks by Megogo

Slide 2

Slide 2 text

About me • Dmitriy Kovalenko @dkovalenko_fun • TeamLead @ x2sy: Megogo • Actively using: Scala, php • Also: Clojure, golang

Slide 3

Slide 3 text

About us • > 4 million users every day • > 30000 hours of video content • Web, iOS, Android, SmartTV, OTT Boxes • CIS, Baltics, Europe

Slide 4

Slide 4 text

Agenda • Caching across tiers: 1. Browser 2. Frontend server/proxy 3. Application • Cache infrastructure • Microservices and caching

Slide 5

Slide 5 text

Speedup your Application

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

• Cache-control • Max-Age, S-Max-Age (seconds) • Expires • ETag (If-None-Match) Headers

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Use CDN, Carl! • Move your Images, JS, CSS -> CDN • Assets minifying, response gzipping

Slide 11

Slide 11 text

Use your Frontend/ Cacher/ Proxy

Slide 12

Slide 12 text

Reverse proxy • Varnish Cache • Nginx • Use your cache store directly (CouchDB, Memcached) • Split your page, think about SSI/ESI includes

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

frontend server caching pros: • High speed • Zero overhead for application • Usually can be applied without application change

Slide 15

Slide 15 text

frontend server caching cons: • Hard to debug • Hard to get right • Changes in application needs additional synchronization

Slide 16

Slide 16 text

Application cache pros: • Much controllable than frontend cache • Can use Application context • Swapping implementations in not a problem

Slide 17

Slide 17 text

Problems to think about • Key selection, Cache Tags • Invalidation schema • Cold start/full flush • Dogpile effect • Embedded or External • Local or Distibuted

Slide 18

Slide 18 text

get('some_key'); if ($data === false) { $data = getFromDB(); $cache->set($data); } return $data;

Slide 19

Slide 19 text

Cache slam problem

Slide 20

Slide 20 text

Eviction strategies • LRU • LFU • FIFO • Lifetime

Slide 21

Slide 21 text

Cache in cluster CP DB Service 2 WEB API Service 2

Slide 22

Slide 22 text

Going further with Microservices

Slide 23

Slide 23 text

There are only two hard things in Computer Science: cache invalidation and naming things. ! -- Phil Karlton

Slide 24

Slide 24 text

Solutions • Nodes list • Shared/Distributed caches • Master invalidates slaves • Queue • Cache cleaner • ETag FTW!

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Great caching is like great sex. It hides all the real problems. ! @vivekhaldar Questions?