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

PPTX
CQRS: Command/Query Responsibility Segregation
PPTX
Introduction to Microservices Patterns
PDF
Dual write strategies for microservices
PDF
Saturn 2018: Managing data consistency in a microservice architecture using S...
PPTX
Apache Kafka - Patterns anti-patterns
PDF
Kong Summit 2018 - Microservices: decomposing applications for testability an...
PDF
Building Event Driven (Micro)services with Apache Kafka
PPTX
Monolithic architecture
CQRS: Command/Query Responsibility Segregation
Introduction to Microservices Patterns
Dual write strategies for microservices
Saturn 2018: Managing data consistency in a microservice architecture using S...
Apache Kafka - Patterns anti-patterns
Kong Summit 2018 - Microservices: decomposing applications for testability an...
Building Event Driven (Micro)services with Apache Kafka
Monolithic architecture

What's hot (20)

PDF
Grokking TechTalk #33: High Concurrency Architecture at TIKI
PPTX
Distributed Transaction in Microservice
PPTX
itlchn 20 - Kien truc he thong chung khoan - Phan 2
KEY
Concurrent Programming Using the Disruptor
PDF
Thiết kế hệ thống E-Commerce yêu cầu mở rộng
PPTX
Stability Patterns for Microservices
PDF
Domain Driven Design và Event Driven Architecture
PPTX
ITLC HN 14 - Bizweb Microservices Architecture
PPSX
LMAX Disruptor as real-life example
PDF
Kinh nghiệm triển khai Microservices tại Sapo.vn
PDF
Bizweb Microservices Architecture
PPTX
Microservices Part 3 Service Mesh and Kafka
PPSX
Event Sourcing & CQRS, Kafka, Rabbit MQ
PPTX
Api gateway in microservices
PDF
The Dual write problem
PPSX
LMAX Disruptor - High Performance Inter-Thread Messaging Library
PPTX
Tiki.vn - How we scale as a tech startup
PPTX
From cache to in-memory data grid. Introduction to Hazelcast.
PPTX
Toi uu hoa he thong 30 trieu nguoi dung
PPTX
Asynchronous processing in big system
Grokking TechTalk #33: High Concurrency Architecture at TIKI
Distributed Transaction in Microservice
itlchn 20 - Kien truc he thong chung khoan - Phan 2
Concurrent Programming Using the Disruptor
Thiết kế hệ thống E-Commerce yêu cầu mở rộng
Stability Patterns for Microservices
Domain Driven Design và Event Driven Architecture
ITLC HN 14 - Bizweb Microservices Architecture
LMAX Disruptor as real-life example
Kinh nghiệm triển khai Microservices tại Sapo.vn
Bizweb Microservices Architecture
Microservices Part 3 Service Mesh and Kafka
Event Sourcing & CQRS, Kafka, Rabbit MQ
Api gateway in microservices
The Dual write problem
LMAX Disruptor - High Performance Inter-Thread Messaging Library
Tiki.vn - How we scale as a tech startup
From cache to in-memory data grid. Introduction to Hazelcast.
Toi uu hoa he thong 30 trieu nguoi dung
Asynchronous processing in big system
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)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Agricultural_Statistics_at_a_Glance_2022_0.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Dropbox Q2 2025 Financial Results & Investor Presentation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Per capita expenditure prediction using model stacking based on satellite ima...
Understanding_Digital_Forensics_Presentation.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
NewMind AI Weekly Chronicles - August'25 Week I
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Digital-Transformation-Roadmap-for-Companies.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

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.