Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

37
Breaking the Monolith Cristobal Viedma Fast Distributed Web Services Using Sets

description

 

Transcript of Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Page 1: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Breaking the Monolith

Cristobal Viedma

Fast Distributed Web Services Using Sets

Page 2: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

What is Viki?

Page 3: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)
Page 4: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)
Page 5: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)
Page 6: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)
Page 7: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Cross-cultural communication and understanding

Page 8: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Technology

Page 9: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Web

viki.com,viki.56.com,

viki.pptv.com,youtube.com,

yahoo.com,msn.com...

Page 10: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Android,iOS,Blackberry,Windows Phone,Samsung Bada,Kindle Fire...

Mobile

Page 11: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

TV

Google TV, Samsung SmartTV, Roku...

Page 12: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Top 5 cities: Singapore, Santiago, La Victoria, Jakarta, New York

Data: viki.com Oct'12

Page 13: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

~22M users, 2500% mobile growth in 2012

Page 14: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

...viewers start leaving if video doesn't play in 2 seconds...

Video Stream Quality Impacts Viewer Behavior: Inferring Causality Using Quasi-Experimental Designs. S. Shunmuga Krishnan, Ramesh K. Sitaraman, 2012

viewers start leaving if video doesn't play in 2 seconds...and every second of additional delay about 6% more viewers jumping ship!

Page 15: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Large ecosystem

Global audience

User growth

Performance

Page 16: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)
Page 17: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Breaking the monolith

Page 18: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)
Page 19: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Platform

Scalability

Availability

Performance

Page 20: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Performance

Network time

Generation time

Render time

Page 21: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Read heavy (writes can wait)

Everything fits in memory

Goal: 25ms uncached (10-100x better)

Essence

Page 22: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Hyperion(platform cluster)

Page 23: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Data structure

Page 24: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Bitmaps

genre:1 -> 010101001genre:2 -> 010010011type:music -> 011000001intersect -> 010000001 (ids: 2 and 9)

Good: speed for intersect & memory efficiencyBad: get the ids and the real data. sorting!, paging...

Page 25: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Everything is a set

genre:1 = [1, 2, 4]type:1 = [1, 2, 5]type:2 = [3, 4]

Good: Sparse (too many 0s with bitmaps) Complexity O(n+m) (m is sets, n elements in the smallest set)genre:1 -> 10 elementsvideos -> 100K elementscomplexity: O(10)

Page 26: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Building our own indexes

Data storedKeeping track of the indexes

How do we find data...redis.call('sort', my_set, 'BY', 'v:*->created_at', 'desc', 'LIMIT', offset, count, 'GET', 'v:*->details')

Page 27: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Old system: not in (id, id, id)first attempt: hash with a list of rulespermutations (too many countries in the world!)CAP -> 10GB. meh~alias matching permutations: 800mb ;)Redis 32bit, even better!

CAP is just another set! (well, but a DIFF!)

Holdbacks

Page 28: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Hacking Redis

Vfind: Building our own Redis function Setlets: Pre-calculated sorted listsMost requests 18~20ms, some cases 100ms (depends on the bigger set)

Vfind only gets content to fill 1 page: 15msPaging just showing more: 9msSerialization of jsons: 5msEnough.. for now!

Page 29: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Lists

A list is just a sorted set. E.g. a list of subscriptions, list of featured content...

Is a set!You can apply holdbacks or any other filter.

Page 30: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

The platform

Page 31: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Each vertical is a source of truth

Logical and operational reasons

Everything routed through api.viki.io

Oceanus(Videos)

Activities (Behaviour)

Many web services

Gaia(Users)

Aphrodite(Community)

Page 32: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Queue

Centralized queue for events and messages

Event-driven web services

Messages must be idempotent

Message / Events Queue

Page 33: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Prometheus

Central logging system

Graphics, stats & logs

Improve visibilityElasticSearch

Logstash Stastd

Graphite

Tasseo /CubismKibana

Logs Stats

Col

lect

ors

Vis

ualiz

atio

ns

Bac

kend

Prometheus(Logs)

Page 34: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

AnalyticsBaboon(CMS)

Subtitling tool

Hyperion(platform cluster)

Hyperion(platform cluster)

Partners

(Samsung, Youtube,Renren...)

Devices

(Android,iPhone, TV...)

Third party developers

(Open API)

Viki.com

(distributed thin-client)

Pla

tform

Clie

nts

Con

tent

Kno

wle

dge

Oceanus(Videos)

Gaia(Users)

Aphrodite(Community)

Subber(Subs,segs)

Message / Events Queue

Prometheus(Logs)

Segmenting tool

Hyperion(platform cluster)

Page 35: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

Web services and API'sCentralized queue for messages

Nothing new...

Page 36: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

... just having fun and learning.

:)

Page 37: Breaking The Monolith: Fast Distributed Web Services Using Sets (Feb13, NUS)

[email protected] btw, we're hiring!