building zingme news feed system

31
Building Zingme News Feed System Chau Nguyen Nhat Thanh Senior Software Manager User Platform Division - VNG

Upload: chau-thanh

Post on 11-Apr-2017

3.972 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Building ZingMe News Feed System

Building Zingme News Feed System

Chau Nguyen Nhat ThanhSenior Software Manager

User Platform Division - VNG

Page 2: Building ZingMe News Feed System

Agenda

1) Introduction to News Feed

2) ZingMe News Feed system history

3) ZingMe News Feed system

4) Some statistics

5) Bonus

6) Q&A

Page 3: Building ZingMe News Feed System

Introduction to News Feed

Page 4: Building ZingMe News Feed System

Introduction to News Feed

● Update friends' info● Update Biz info● Update VIP info● Interaction to them by comment, like ...

Page 5: Building ZingMe News Feed System

Introduction to News Feed

Page 6: Building ZingMe News Feed System

Introduction to News Feed

Page 7: Building ZingMe News Feed System

Introduction to News Feed

Page 8: Building ZingMe News Feed System

Introduction to News Feed

● Terms● Social graph: Users in most social networking

sites are describable in terms of a social graph. The relationships between users are represented by adjacency lists. If Jack and Jill are friends, they are said to be adjacent. This is known as an "edge" in the graph. (from Quora)

● Not only Friends ● but also Followers …

Page 9: Building ZingMe News Feed System

Introduction to News Feed

● What do we need?● Someone does actions, his friend will see these

action in his home as soon as possible

● What will we solve the problems?● Solution 1: Push model (fan out on write)● Solution 2: Pull model (fan out on read)● Solution 3: Mixing push and pull (Feeding

Frenzy- a paper from Yahoo)

Page 10: Building ZingMe News Feed System

Introduction to News Feed

● Push model● This method involves denormalizing the user's activity

data and pushing the meta data to all the user's friends at the time it occurs. (from Quora)

● Pull model● This method involves keeping all recent activity data in

memory and pulling in (or fanning out) that data at the time a user loads their home page. Data doesn't need to be pushed out to all subscribers as soon as it happens, so no back-log and no disk seeks (from Quora)

● Mix model● Active user using push model● Non active user using pull

Page 11: Building ZingMe News Feed System

ZingMe News Feed system history

Page 12: Building ZingMe News Feed System

ZingMe News Feed system history

● First version● Using PHP for worker● Using MySQL for feed item● Using MySQL for feed indexing● Having full feature: feed type filtering, ignoring

users ..● Restarting DB and other services are the favorite

jobs at that time :)● Lesson learn:

– Relation DB may not be fit for this kind of project

Page 13: Building ZingMe News Feed System

ZingMe News Feed system history

● Second version● Still using PHP for worker● Using Cassandra for feed item● Using home build list id service for feed indexing● Using Memcached for caching item● Removing all deluxe features :) (stupid features due to

our limited technique)● Restarting Cassandra, and waiting for compaction is our

favorite jobs :) :)● Headache with changing avatar● Lesson learn: believe only ourself

Page 14: Building ZingMe News Feed System

ZingMe News Feed system history

● Third version● Moving to Java for better performance● Still using Cassandra for feed item● Trying to use redis in Lab● Keep only simple features (KISS)● Cannot control memcache

– The new one expired before the old one ???– Memcached is wrong ???

● Cannot believe to Cassandra● Lesson learn: memcached is not the “thuốc tiên” :)

Page 15: Building ZingMe News Feed System

ZingMe News Feed system

(The current one :))

Page 16: Building ZingMe News Feed System

ZingMe News Feed system

Page 17: Building ZingMe News Feed System

ZingMe News Feed system

● Still using push model because of Twitter public some info related to this model

● Not enough technical when choosing pull model● Begin to understand a little bit about how to keep it

scaling● Do not use Cassandra any more for such kind of this

system → do not believe to anyone, learn from what they do and try our best

Page 18: Building ZingMe News Feed System
Page 19: Building ZingMe News Feed System

ZingMe News Feed system

● Feed Item● UserId, ObjectId, Created date...● Storage: home build based on Kyoto Cabinet● Fast recovery when crash

● Feed Index● UserId → [feedId1,feedId2...]● Storage: home build● Fast recovery when crash

Page 20: Building ZingMe News Feed System

ZingMe News Feed system

● Rate limit● Prefilter Spam or auto tool based on rate of write request● When hit limit, block that user for amount of time

● Feed writer● Receive the write command● Get the next Id from Generator● Push the item to queue● Return the feedId for future reference

Page 21: Building ZingMe News Feed System

ZingMe News Feed system

● Gearman feed storage queue● Very fast● Support multi language client● Some time block the all workers when network

unstable :) ● Solve most of our heavy jobs

Page 22: Building ZingMe News Feed System

ZingMe News Feed system

● Feed Sync center● Sync the new feed to the others such as:

– Spam detection– Feed ranking system– Logging system

● Feed replication function for future use

Page 23: Building ZingMe News Feed System

ZingMe News Feed system

● Feed Render worker● The main and heavy job:

– Get the feed item– Extract the template id– Get user info– Render the feed based on them

● Put rendered feed in to appropriate cache● Mobile and Desktop are totally different

Page 24: Building ZingMe News Feed System

ZingMe News Feed system

● Feed Aggregate● Get the feed index● Get the rendered item from cache● Return to the front-end● Some cheat:

– If the cached items less than 5, in stead of returning the data return a JavaScript to reload that list

– At the same time push a task to warm-up the rendered cache

● Auto fail-over when a cache service die

Page 25: Building ZingMe News Feed System

Some statistics

Page 26: Building ZingMe News Feed System

Some statistics

● ~15M actions / day● 10% Spam

● Gift receive● Meaningless status

● Cache hit 98%● ~80M registered users● ~3M active users / days● Max 1000 friends only● Unlimited followers

Page 27: Building ZingMe News Feed System

Bonus● Twemcache (https://github.com/twitter/twemcache)

● From Twitter● Solve most problems with memcached● More strategy for eviction items

– Item LRU eviction: per-slabclass LRU eviction– Random eviction : evict all items from a randomly chosen slab– ...

● Twemcache proxy

● Redis (http://redis.io)● Replacement for home build when you have not enough time● Set is default supported● Supported cluster● Persistence

Page 28: Building ZingMe News Feed System

Question and Answer

Page 29: Building ZingMe News Feed System

Q&A

● What is the problem with followers?● Do that with the trick● Cheating the owner ;)

Page 30: Building ZingMe News Feed System

We are hiring!!!!!!!

Page 31: Building ZingMe News Feed System

Q&A

Contact info: Chau Nguyen Nhat Thanh

[email protected] me.zing.vn/thanhcnn2000