SlideShare a Scribd company logo
16
Most read
20
Most read
21
Most read
High Concurrency
Architecture
09-2019. TIKI.VN
Contributors
Bùi Anh Dũng
Principal Engineer
Nguyễn Hoàng Bách
Senior Principal
Engineer
Phan Công Huân
Senior Software
Engineer
Lê Minh Nghĩa
Senior Architect
Trần Nguyên Bản
Principal Engineer
Agenda
- Principles
- Pegasus - Highest throughput API
- Arcturus - High concurrency inventory API
- Conclusion
Principles
- Use local memory to handle high concurrency transaction
- Non blocking architecture
- Trade-offs consistency vs eventual consistency
- Reliable replication
- Authority: each service owns its problems.
Pegasus - Highest Throughput API at TIKI
Problems:
- Handle the most of traffic to fetch product information
- Has to handle at least 10k request/s, tp95 < 5ms
Pegasus - Architecture
Pegasus - Architecture
Practises:
- Cache product data in local memory
- Subscribe product change event to
invalid cache
- Non-Blocking http web server
- Compress to reduce payload size
Technology:
- Java
- Guava - In Memory Cache
- Gridgo - Async IO & Event driven
framework
Pegasus - Compression
Two cases:
- Get single product by id
- Get multiple product by a list id
Solutions:
- Using gzip to compress product data to store in
cache. Reduce from 200kb text to 3Kb
- Handle single product request: return
compressed gzip bytes to client directly
- Handle multiple product request: store plain
product data and merge them to build a list of
products, then use Snappy format to compress
data and return to client
- Gzip format compress better than Snappy and
is supported natively by most http client, but
Snappy compress faster and use less CPU
- Output cache can be enabled in hot-deal
situation
Pegasus - Technology
- Java
- Gridgo
- Guava
- Kafka
Pegasus - Benchmark
Benchmark use WRK tools, 4VM,
L4 LB, GCP:
- 90%<6.6ms
- 96k request/s
Production
- 200k request/minutes (all
platforms)
- <2ms
Cache hit: 85%. Increased to 95% with Consistent Hashing With Bounded Load.
Average payload: Single (3KB), Multi (60KB)
Pegasus - Benchmark/Replication
Arcturus - High concurrency Inventory API
Problems:
- Handle inventory transaction when customers place orders
- Handle high concurrency transaction for extreme hot deals with very cheap
and low quantity. Exp: Only ten 1đ iPhone XS, only in ten minutes from 9AM
to 9h10 AM.
- Guarantee eventual consistency of inventory data between many systems
Arcturus - Context Diagram
Arcturus - Architecture
Arcturus - Problems and Solutions
Problems:
- Many customers may place order at the same time, especially for hot skus.
- System has to be deterministic and can be recovered after crashing
Solutions:
- All write requests are published to Kafka with only one partition to guarantee
the ordering of message and recover if system crashes.
- Non Blocking In Memory Cache for both read and write
- All changes are flushed to database asynchronously
- Recovery based on the offset of write command
Arcturus - In Memory Cache Data Structure
Problem:
- There will be a race condition when many
customer place the same skus at the
same time
- Building an in memory cache structure
that can buffer data changes and flush to
database asynchronously
Approach:
- Each record have a key (string, bytes…)
and a value (8 bytes long number).
- A transaction is a set of record updates.
- Transactions must be ordered (e.g. key_1
must +3 before can be -1).
- It can be millions of keys and process upto
10k TPS.
- Using ring buffer data structure to
guarantee the ordering of changes
* The hardest thing is to keep
everything ordered when make it
fast enough.
Arcturus - Old solution
- Multi threading application
- DB transaction, row locking
Pros
- Strong consistency
- Simple implementation
Cons
- Slow
- Deadlock/timeout implicit risk
Arcturus - LMax Architecture
- Non Blocking architecture using single
thread business logic processor
- Use Ring Buffer data structure to
communicate between processors
- Handle million transaction per seconds
Arcturus - Batching marshaller
vBatching: use multi thread marshaller
● Pros
- Fast (400k-600k ops/s*)
- Avoid multi key locking
- Write only most updated value
● Cons
- Inconsistent transaction offset
→ use when you just want to make your code as fast
as possible.
* Macbook pro 2016 15’’ 2.7GHz Core i7, 16G ram. Without I/O, single update per
transaction
*** Test without I/O: [Single ops vbatch] Total time running for 1000000 transactions: 1085 ms; at rate: 921,658.99 ops/s
Arcturus - Batching marshaller
hBatching: use single marshaller thread
● Pros
- Ensure transaction offset
- Ordered db updating
● Cons
- A little bit slower than vBatching.
→ use when you need to re-create application state
after fail.
*** Test without I/O: [Single ops hbatch] Total time running for 1000000 transactions: 1056 ms; at rate: 946,969.70 ops/s
Arcturus - Recovery/Replay
Arcturus - Technology
- Java
- Kafka
- ZeroMQ
- Gridgo
- MySQL
- LMax/Ring Buffer
Conclusion
- Has to trade-off between consistency and eventual consistency
- In Memory is a great way to improve the performance
- Reliable replication is the key to split and scale system
- Non Blocking architecture is a great way to utilize hardware resources
efficiently.

More Related Content

PDF
Dual write strategies for microservices
PDF
Netflix Global Cloud Architecture
PDF
eBay Architecture
PDF
Building Event Driven (Micro)services with Apache Kafka
PPTX
CQRS: Command/Query Responsibility Segregation
PPTX
Microservices Decomposition Patterns
PDF
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
PPTX
Apache Kafka - Patterns anti-patterns
Dual write strategies for microservices
Netflix Global Cloud Architecture
eBay Architecture
Building Event Driven (Micro)services with Apache Kafka
CQRS: Command/Query Responsibility Segregation
Microservices Decomposition Patterns
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Apache Kafka - Patterns anti-patterns

What's hot (20)

PDF
Grokking TechTalk #33: High Concurrency Architecture at TIKI
PPTX
Distributed Transaction in Microservice
PDF
Bizweb Microservices Architecture
PPTX
ITLC HN 14 - Bizweb Microservices Architecture
PDF
Thiết kế hệ thống E-Commerce yêu cầu mở rộng
PDF
Kinh nghiệm triển khai Microservices tại Sapo.vn
PDF
Domain Driven Design và Event Driven Architecture
PPTX
Tiki.vn - How we scale as a tech startup
PDF
LMAX Architecture
PDF
Sapo Microservices Architecture
PPSX
Event Sourcing & CQRS, Kafka, Rabbit MQ
PPTX
Kafka replication apachecon_2013
KEY
Redis overview for Software Architecture Forum
PDF
Building Bizweb Microservices with Docker
PDF
Grokking Techtalk #39: How to build an event driven architecture with Kafka ...
PPTX
HBase and HDFS: Understanding FileSystem Usage in HBase
PDF
CQRS + Event Sourcing
PPTX
Software architecture for high traffic website
PDF
From Mainframe to Microservice: An Introduction to Distributed Systems
PDF
Under the Hood of a Shard-per-Core Database Architecture
Grokking TechTalk #33: High Concurrency Architecture at TIKI
Distributed Transaction in Microservice
Bizweb Microservices Architecture
ITLC HN 14 - Bizweb Microservices Architecture
Thiết kế hệ thống E-Commerce yêu cầu mở rộng
Kinh nghiệm triển khai Microservices tại Sapo.vn
Domain Driven Design và Event Driven Architecture
Tiki.vn - How we scale as a tech startup
LMAX Architecture
Sapo Microservices Architecture
Event Sourcing & CQRS, Kafka, Rabbit MQ
Kafka replication apachecon_2013
Redis overview for Software Architecture Forum
Building Bizweb Microservices with Docker
Grokking Techtalk #39: How to build an event driven architecture with Kafka ...
HBase and HDFS: Understanding FileSystem Usage in HBase
CQRS + Event Sourcing
Software architecture for high traffic website
From Mainframe to Microservice: An Introduction to Distributed Systems
Under the Hood of a Shard-per-Core Database Architecture
Ad

Similar to High Concurrency Architecture at TIKI (20)

PPTX
Mykhailo Hryhorash: Архітектура IT-рішень (Частина 1) (UA)
PDF
Tweaking performance on high-load projects
PDF
Service-Oriented Design and Implement with Rails3
PPTX
Mykhailo Hryhorash: Архітектура IT-рішень (Частина 1) (UA)
PPTX
Black Friday and Cyber Monday- Best Practices for Your E-Commerce Database
PDF
Big Trouble in Little Networks, new and improved
PDF
Scalability broad strokes
KEY
High performance network programming on the jvm oscon 2012
PPTX
Flashback: QCon San Francisco 2012
PPTX
Skeuomorphs, Databases, and Mobile Performance
PDF
Architecture Patterns - Open Discussion
PPTX
Skeuomorphs, Databases, and Mobile Performance
PDF
Can Your Mobile Infrastructure Survive 1 Million Concurrent Users?
PDF
Preparing your web services for Android and your Android app for web services...
PDF
Rest on steroids
PPTX
First spring
PPTX
Leapfrogging with legacy
KEY
Synchronous Reads Asynchronous Writes RubyConf 2009
PDF
Scalability Considerations
PDF
Voldemort Nosql
Mykhailo Hryhorash: Архітектура IT-рішень (Частина 1) (UA)
Tweaking performance on high-load projects
Service-Oriented Design and Implement with Rails3
Mykhailo Hryhorash: Архітектура IT-рішень (Частина 1) (UA)
Black Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Big Trouble in Little Networks, new and improved
Scalability broad strokes
High performance network programming on the jvm oscon 2012
Flashback: QCon San Francisco 2012
Skeuomorphs, Databases, and Mobile Performance
Architecture Patterns - Open Discussion
Skeuomorphs, Databases, and Mobile Performance
Can Your Mobile Infrastructure Survive 1 Million Concurrent Users?
Preparing your web services for Android and your Android app for web services...
Rest on steroids
First spring
Leapfrogging with legacy
Synchronous Reads Asynchronous Writes RubyConf 2009
Scalability Considerations
Voldemort Nosql
Ad

Recently uploaded (20)

PPTX
TLE Review Electricity (Electricity).pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Spectroscopy.pptx food analysis technology
PPT
Teaching material agriculture food technology
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Approach and Philosophy of On baking technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
TLE Review Electricity (Electricity).pptx
Machine Learning_overview_presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Spectroscopy.pptx food analysis technology
Teaching material agriculture food technology
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
A comparative analysis of optical character recognition models for extracting...
Network Security Unit 5.pdf for BCA BBA.
Univ-Connecticut-ChatGPT-Presentaion.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Heart disease approach using modified random forest and particle swarm optimi...
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
OMC Textile Division Presentation 2021.pptx
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Approach and Philosophy of On baking technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

High Concurrency Architecture at TIKI

  • 2. Contributors Bùi Anh Dũng Principal Engineer Nguyễn Hoàng Bách Senior Principal Engineer Phan Công Huân Senior Software Engineer Lê Minh Nghĩa Senior Architect Trần Nguyên Bản Principal Engineer
  • 3. Agenda - Principles - Pegasus - Highest throughput API - Arcturus - High concurrency inventory API - Conclusion
  • 4. Principles - Use local memory to handle high concurrency transaction - Non blocking architecture - Trade-offs consistency vs eventual consistency - Reliable replication - Authority: each service owns its problems.
  • 5. Pegasus - Highest Throughput API at TIKI Problems: - Handle the most of traffic to fetch product information - Has to handle at least 10k request/s, tp95 < 5ms
  • 7. Pegasus - Architecture Practises: - Cache product data in local memory - Subscribe product change event to invalid cache - Non-Blocking http web server - Compress to reduce payload size Technology: - Java - Guava - In Memory Cache - Gridgo - Async IO & Event driven framework
  • 8. Pegasus - Compression Two cases: - Get single product by id - Get multiple product by a list id Solutions: - Using gzip to compress product data to store in cache. Reduce from 200kb text to 3Kb - Handle single product request: return compressed gzip bytes to client directly - Handle multiple product request: store plain product data and merge them to build a list of products, then use Snappy format to compress data and return to client - Gzip format compress better than Snappy and is supported natively by most http client, but Snappy compress faster and use less CPU - Output cache can be enabled in hot-deal situation
  • 9. Pegasus - Technology - Java - Gridgo - Guava - Kafka
  • 10. Pegasus - Benchmark Benchmark use WRK tools, 4VM, L4 LB, GCP: - 90%<6.6ms - 96k request/s Production - 200k request/minutes (all platforms) - <2ms Cache hit: 85%. Increased to 95% with Consistent Hashing With Bounded Load. Average payload: Single (3KB), Multi (60KB)
  • 12. Arcturus - High concurrency Inventory API Problems: - Handle inventory transaction when customers place orders - Handle high concurrency transaction for extreme hot deals with very cheap and low quantity. Exp: Only ten 1đ iPhone XS, only in ten minutes from 9AM to 9h10 AM. - Guarantee eventual consistency of inventory data between many systems
  • 15. Arcturus - Problems and Solutions Problems: - Many customers may place order at the same time, especially for hot skus. - System has to be deterministic and can be recovered after crashing Solutions: - All write requests are published to Kafka with only one partition to guarantee the ordering of message and recover if system crashes. - Non Blocking In Memory Cache for both read and write - All changes are flushed to database asynchronously - Recovery based on the offset of write command
  • 16. Arcturus - In Memory Cache Data Structure Problem: - There will be a race condition when many customer place the same skus at the same time - Building an in memory cache structure that can buffer data changes and flush to database asynchronously Approach: - Each record have a key (string, bytes…) and a value (8 bytes long number). - A transaction is a set of record updates. - Transactions must be ordered (e.g. key_1 must +3 before can be -1). - It can be millions of keys and process upto 10k TPS. - Using ring buffer data structure to guarantee the ordering of changes * The hardest thing is to keep everything ordered when make it fast enough.
  • 17. Arcturus - Old solution - Multi threading application - DB transaction, row locking Pros - Strong consistency - Simple implementation Cons - Slow - Deadlock/timeout implicit risk
  • 18. Arcturus - LMax Architecture - Non Blocking architecture using single thread business logic processor - Use Ring Buffer data structure to communicate between processors - Handle million transaction per seconds
  • 19. Arcturus - Batching marshaller vBatching: use multi thread marshaller ● Pros - Fast (400k-600k ops/s*) - Avoid multi key locking - Write only most updated value ● Cons - Inconsistent transaction offset → use when you just want to make your code as fast as possible. * Macbook pro 2016 15’’ 2.7GHz Core i7, 16G ram. Without I/O, single update per transaction *** Test without I/O: [Single ops vbatch] Total time running for 1000000 transactions: 1085 ms; at rate: 921,658.99 ops/s
  • 20. Arcturus - Batching marshaller hBatching: use single marshaller thread ● Pros - Ensure transaction offset - Ordered db updating ● Cons - A little bit slower than vBatching. → use when you need to re-create application state after fail. *** Test without I/O: [Single ops hbatch] Total time running for 1000000 transactions: 1056 ms; at rate: 946,969.70 ops/s
  • 22. Arcturus - Technology - Java - Kafka - ZeroMQ - Gridgo - MySQL - LMax/Ring Buffer
  • 23. Conclusion - Has to trade-off between consistency and eventual consistency - In Memory is a great way to improve the performance - Reliable replication is the key to split and scale system - Non Blocking architecture is a great way to utilize hardware resources efficiently.