[Case Simulation Workshop] Michael Evans - High performance system building
-
Upload
innovatube -
Category
Technology
-
view
131 -
download
1
Transcript of [Case Simulation Workshop] Michael Evans - High performance system building
Introduction❖ Graduated: Ha Noi University of Science and
Technology - Software Engineer - 2010
❖ Got No.3, Viet Name Talent in IT field - 2011.
❖ from 2007 - 2013: work at Med-Aid as Team Leader, a partner of Prowess.
❖ From 2013 - Now: working at Cinnamon as Software Architecture Leader.
Main points researching❖ High performance system building
❖ Data mining
❖ Artificial Intelligent
How to build high performance system?
Normal system architecture
database
System logic
Server side
Third party
system
Client side
Problem come from here!!!
Real use case❖ Social network
❖ one user have: followers, followings, posts.
❖ …
Server side - Database
Database issues?
Queries So slow
- Multiple queries in one request
- Each query take time to run System run slow
Database solution?
Queries So slow
❖ Set Index for all important fields
❖ Optimise number of queries on each request / task
❖ Anything else?
Caching solution
❖ always check if needed data exist on cache or not
❖ if exist —> get from cache.
❖ if not —> query from DB and add to cache too.
Logic
CacheExist?
Query if not exist in cache
Update cache for each query
Caching solution❖ Redis cache: https://redis.io
❖ Memcache: https://memcached.org
❖ …
Example
❖ If User 1111 create new post which has ID = cccc —> system need update that post id for all his following users.
❖ How will you do?
UserId PostId2222 aaaa2222 bbbb3333 aaaa
Feeds table
UserId FollowingID1111 22221111 33331111 4444
Following table
Normal way❖ Step 1: Get all following user’s ids from 1111. (0.2s)
❖ Step 2: For each following users:
❖ Step 2.1: Insert new record on Feeds table for that user. (0.2s)
❖ If 1111 have 50 following —> system will take: 0.2 + 50*0.2 = 10.2s !!!! —> Too slow!!!
Improved way❖ Step 1: Get all following user’s ids from 1111. (0.2s)
❖ Step 2: For each following users:
❖ Step 2.1: Create feed’s record for each user. (so small time)
❖ Step 3: Insert all records in one command. (0.3s)
❖ If 1111 have 50 following —> system will take: 0.2 + 0.3 = 0.5s !!!! —>Much faster!!!
Apply cache?❖ Step 1: Get all following user’s ids from cache. (0.002s)
❖ Step 2: For each following users:
❖ Step 2.1: Create feed’s record for each user. (so small time)
❖ Step 3: Insert all records in one command. (0.3s)
❖ Step 4: Insert all records to cache. (0.003s)
❖ If 1111 have 50 following —> system will take: 0.002 + 0.3 + 0.003 = 0.305s !!!! —>Much faster!!!
Server side - Logic
Server side - Logic❖ POST / PUT/ DELETE
❖ GET
Third party
Data databaseLogic
SLOW
Third party
DataLogic
SLOW
database
Third party
POST/PUT/DELETE issues?
Tasks need to do
Database
Third Party
Request
Response time > 2s
Too much tasks need to do
POST/PUT/DELETE solution?Database
Third Party
Request
Response time < 500 ms
Realtime
Background
How background work?❖ It should be use message queue system.
❖ some message queue system: RabbitMQ, ZeroMQ, Kafka, Redis PubSub…
Main server
Message queue
Background server 1
Background server 2
Messaging queue technology❖ PubSub pattern (AMQP, MQTT…)
Can we make Realtime task run faster?
Caching for realtime task
Task 1
Access DB
Task 2
Update DB
….
OLD way
Task 1
Access Cache
Task 2
Update Cache
….
NEW way
Task n Task n
Example❖ when new post created by user 1111 —> push
notification for all following users about that.
❖ How will you do?
Normal way❖ User create new post
❖ Get all following user ids.
❖ for each following user:
❖ Insert new record to Feed table
❖ call push notification method to send push notification.
❖ Return result.
So take time here
Improved way❖ User create new post
❖ Get all following user ids.
❖ Insert all records in one command into Feed table
❖ For each following users:
❖ Add one task to message queue to run in background.
❖ Return result.
So Fast
GET issues?
Data queries
Database
Third Party
Request
Response time > 2s
Too much thing need to format
Format response data
Too slow
Solution
Data queries
Database
Third Party
Request
Response time <500ms
Format response data
Cache
How to make cache data optimise for GET apis?
API get list of
following users
Get following Ids
Format following
objects
Following cache
Following formatted
cache
Always have cache object for any data we need for our apis.
How to apply them to your project / company?
Modulation
Modulation
Libs
Micro services
Libs
Cache
DB Access
Cache Access
Repository Base
Your Repository Here
Micro-service
Main logic
Message queue
Background server
Background server
….