SlideShare a Scribd company logo
Asymmetric

Replication

Architecture
Improve Item Listing Performance Using Couchbase,
With Asynchronous Replication Approach
Intae Kim | Technical Lead/Architect, Ticketmonster
Company Information:
• Service Name: TMON
• #1 Social Commerce in Korea
• 10,000,000+ user
• NOW HIRING(?!)
TICKET MONSTER
let the game begin
porting legacy API without changing master databases,

introducing NoSQL(Couchbase) & Message Queue(RabbitMQ)
to enhance data consumption flow
abstract:
Agenda:
• Open The Pandora’s Box
• Think Outside The Box
• Prototyping The Box
• Implementing Brand New Box
• Retrospective; Wrap It Up
Open The Pandora’s Box
Most BEAUTIFUL Code Ever Seen… (Are You Serious?)
Mission:
• Porting Current PHP into Java
• + Migrate Category Mappings(!)
• + Resolve Hard-Coded(!!)
ok, let’s go…
item list
• title, image, price
• discount
• sales count
• categories
• pagination
• sort order
• tags
• …
but…
Measurement, #1/2:
Measurement, #2/2:
anyway, keep going…
List API - Call Tree:
List API - Complexity:
• 2000+ function call
• 20+ call tree depth
• cyclic dependency
• NO history, NO documentation, …
• …
welcome to hell
List API - Performance:
• 120+ sec response duration1)
• 40+ table, 10+ RPC reference
• table joins, OUTER joins
• O(N4) loop statement
• …
1) without cache
List API - etc:
• promiscuous cache coating
• side effect friendly functions
• black box parameters
• lying/obsolete comments
• …
a nightmare
Think Outside The Box
Asynchronous Data Replication & Simple Data Read
Pandora’s Box Architecture:
user

service
40+ tables
admin

console
client
slave

(MySQL)master

(MySQL)
adjustment
C/R/U/D
update “list” order
fetch “list”
10+ RPCs
Pandora’s Box:
• Typical Web Application
• Homogeneous, Symmetric Master - Slave
• Synchronous
• Primeval Cache
• Monolith
API Result, Mixed Up 40+ Tables:
should be on-demand?
Asymmetric Box Architecture:
C/R/U/D
user

service
SIMPLE

query
replication40+ tables
admin

console
NoSQL replica

(Couchbase)
item “list”
composite json
client
item data
master

(MySQL)
adjustment
purchase data
10+ RPCs
Asymmetric Box:
• Heterogeneous, Asymmetric Master - Slave
• Asynchronous
• Parallel Data Processing
• NO Join
• NO Cache
• MSA-like
The Key:
• READ: frequent, ~109 request / day
• WRITE: rare, ~ 106 request / day
Prototyping The Box
Concept Verification for Data Change & On-Demand Listing
List Query on Legacy:
user

service
40+ tables
client
slave

(MySQL)
admin

console
master

(MySQL)
adjustment
C/R/U/D
update “list” order
fetch “list”
10+ RPCs
On-Demand List Calculation
C/R/U/D
replication40+ tables
admin

console
composite json
master

(MySQL)
item data
adjustment
purchase data
List Query on Couchbase:
user

service
SIMPLE Query
NoSQL replica

(Couchbase) client
The Difference:
40+ tables
10+ RPCs
On-Demand Calculation with 40+ Tables, 10+ RPCs
Simple, Single Table Access
Legacy - User Request Part
Alternative - User Request Part
Replication Datastore Candidates:
• redis
• MongoDB
• Couchbase
• RDBMS
why couchbase?
Struggle #1 - NoSQL:
• how to query for sorted, filtered?
• how to design data modeling?
Couchbase “View Query”:
• Map-Reduce
• Eventually Consistent
• B-Tree
• Functional
the ouroboros dream
{	
				"id"	:	12345678,	
				"title"	:	"Awesome	Deal",	
				"price"	:	10000,	
				"foo"	:	"bar",	
				...	
				"meta"	:	{	
								"categories"	:	[111,	222,	333],	
								"score"	:	2.71828,	
								"type"	:	"DEAL"	
				},	
				...	
				"is_awesome"	:	true,	
				"start_date"	:	"2015-08-25	00:00:00",	
				"end_date"	:	"2016-01-22	00:00:00"	
}	
Document Data Modeling:
function	(doc,	meta)	{

				if	(doc.meta.type	!=	"DEAL")	{

								return;

				}



				var	categories	=	doc.meta.category;

				var	start_date	=	Number(doc.start_date.split('	')[0].replace(/-/g,	''));



				for	(var	i	=	0;	i	<	categories.length;	i++)	{

								emit([categories[i],	start_date,	doc.id],	[doc.is_awesome]);

				}

}

Couchbase View - Map Function:
prototyping with python
Data Scraping for Prototyping:
Couchbase
Scrape, Scrape, Scrape, …
import	json,	httplib	
from	gcouchbase.bucket	import	Bucket	
template	=	'/****list/list?cat*=%s&page=%s&page_size=50'	
http	=	httplib.HTTPConnection('****.ticketmonster.co.kr',	timeout=500)	
bucket	=	Bucket('couchbase://localhost/prototype',	password='****')	
sliced	=	[[…],	[…],…]	
def	run_each_slice(sliced_categories):	
				for	category	in	sliced_categories:	
								page,	total	=	0,	0	
								while(True):	
												http.request('GET',	template	%	(category,	page))	
												data	=	http.getresponse().read()	
												http.close()	
												for	deal	in	json.loads(data)['lists'][0]['deals']:	
																bucket_work('deal_replica::%d'	%	deal['id'],	deal,	category)	
for	each	in	sliced:	
				run_each_slice(each)
Data Scraper Script(199 LoC):
Prototyping List Query:
Couchbase
Fetch “ORDERED” List with:

- offset

- limit

- CATEGORY
import	json	
from	gcouchbase.bucket	import	Bucket	
bucket	=	Bucket('couchbase://localhost/prototype',	password='****')	
results	=	bucket.query('deals',	‘date_ordered_view',	
								limit	=	100,	
								skip	=	0,	
								mapkey_range	=	[[12345,	'99999999'],	[12345,	'00000000']],	
								descending	=	True,	
								include_docs	=	True,	
								reduce	=	False	
)	
for	item	in	results:	
				print	item	
List Query Script(22 LoC):
ready to rock n’ roll
Implementing Brand New Box
Asynchronous Data Replication
Struggle #2 - Read Legacy:
• an epic
• associative array abuse
• fickle parameters
2 weeks to read
Skill Set:
• Java, Python, Javascript, PHP
• RxJava, jOOQ, SpringMVC, Jersey
• Flask, gevent, greenlet
• Couchbase, MySQL, RabbitMQ, Tomcat
Methodology:
• Test Driven Development
• Pseudo-Agile Process
Measurement, #1/2:
Measurement, #2/2:
Retrospective; Wrap It Up
So Far, So Good… So What?
overwhelming performance
CENSORED
48ms
CENSORED
140,174ms
simple & clean code
List<FixedDeal>	fixed	=	fixedDealService.find(cid,	bid);	
FixedDealPagination	pagination	=	FixedDealPagination.paginate(fixed,	limit);	
FixedDealPage	currentPage	=	pagination.find(pageNo);	
PaginationOffset	offset	=	PaginationOffset.adjust(currentPage);	
List<String>	plain	=	plainDealService.find(cid,	bid,	offset);	
List<String>	collatedIds	=	PageRankCollator.collate(currentPage,	plain)	
return	Observable.from(collatedIds)	
								.concatMapEager(repository::get)	
								.map(JsonDocument::content)	
								.map(stickerFilter::apply)	
								.map(priceFilter::apply)	
								.map(viewAttributeFilter::apply);
Query on Couchbase:
@Repository

public	class	DealImageRepository	{

				static	final	Table	DEAL_IMAGES	=	table("deal_images");



				static	final	Field	ID						=	field("id",						long.class);

				static	final	Field	IMG_KEY	=	field("img_key",	String.class);

				static	final	Field	IMG_VAL	=	field("img_val",	String.class);



				@Autowired	
				@Qualifier(value	=	Database.MASTER)	
				DSLContext	conn;



				public	List<DealImage>	findById(long	dealNo)	{

								Select	sql	=	conn.select(ID,	IMG_KEY,	IMG_VAL)

																.from(DEAL_IMAGES)

																.where(ID.equal(dealNo));

								return	sql.fetch().into(DealImage.class);

				}

}

Collect Master Data using jOOQ:
Measurement Compare #1/3 - LoC:
Measurement Compare #2/3 - Debt:
Measurement Compare #3/3 - Issues:
is it all?
what made the monster?
(…bragging…)
Spring Camp 2016 - List query performance improvement using Couchbase
EOF
ikim@tmon.co.kr
greatkit@gmail.com

More Related Content

PPTX
Apache Gobblin at MZ
PDF
Cassandra at Vast
KEY
KeyValue Stores
KEY
HAProxyでMySQL HA on Amazon EC2
PDF
Production Ready Serverless Java Applications in 3 Weeks AWS UG Cologne Febru...
PDF
Kafka Summit SF 2017 - Shopify Flash Sales with Apache Kafka
PPTX
Python Ireland Conference 2016 - Python and MongoDB Workshop
PPT
The NoSQL Way in Postgres
 
Apache Gobblin at MZ
Cassandra at Vast
KeyValue Stores
HAProxyでMySQL HA on Amazon EC2
Production Ready Serverless Java Applications in 3 Weeks AWS UG Cologne Febru...
Kafka Summit SF 2017 - Shopify Flash Sales with Apache Kafka
Python Ireland Conference 2016 - Python and MongoDB Workshop
The NoSQL Way in Postgres
 

What's hot (10)

PDF
Samba distributed env
PDF
Technologies, Data Analytics Service and Enterprise Business
PDF
Postgres NoSQL - Delivering Apps Faster
 
PPTX
Compare DynamoDB vs. MongoDB
KEY
MongoDB, E-commerce and Transactions
PPTX
Lots of facets, fast
PDF
NoSQL on ACID - Meet Unstructured Postgres
 
PDF
Ruby and Distributed Storage Systems
PDF
To Have Own Data Analytics Platform, Or NOT To
PDF
No sql way_in_pg
Samba distributed env
Technologies, Data Analytics Service and Enterprise Business
Postgres NoSQL - Delivering Apps Faster
 
Compare DynamoDB vs. MongoDB
MongoDB, E-commerce and Transactions
Lots of facets, fast
NoSQL on ACID - Meet Unstructured Postgres
 
Ruby and Distributed Storage Systems
To Have Own Data Analytics Platform, Or NOT To
No sql way_in_pg
Ad

Similar to Spring Camp 2016 - List query performance improvement using Couchbase (20)

PPTX
NoSQL: Cassadra vs. HBase
PDF
Scala at foursquare
PPTX
SQLCAT: Tier-1 BI in the World of Big Data
PDF
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
PPTX
SQL To NoSQL - Top 6 Questions Before Making The Move
PPTX
Agility and Scalability with MongoDB
PDF
Using Spring with NoSQL databases (SpringOne China 2012)
PDF
Hbase Nosql
PDF
MongoDB: a gentle, friendly overview
PDF
Spring one2gx2010 spring-nonrelational_data
PPT
Wmware NoSQL
PDF
Apache Drill talk ApacheCon 2018
PDF
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
PPTX
Introduction to NoSQL
PDF
High-Performance Storage Services with HailDB and Java
PPTX
Meetup#2: Building responsive Symbology & Suggest WebService
PPT
No sql Database
PPTX
Master tuning
PDF
ログ収集プラットフォーム開発におけるElasticsearchの運用
PPTX
Webinar - Macy’s: Why Your Database Decision Directly Impacts Customer Experi...
NoSQL: Cassadra vs. HBase
Scala at foursquare
SQLCAT: Tier-1 BI in the World of Big Data
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
SQL To NoSQL - Top 6 Questions Before Making The Move
Agility and Scalability with MongoDB
Using Spring with NoSQL databases (SpringOne China 2012)
Hbase Nosql
MongoDB: a gentle, friendly overview
Spring one2gx2010 spring-nonrelational_data
Wmware NoSQL
Apache Drill talk ApacheCon 2018
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
Introduction to NoSQL
High-Performance Storage Services with HailDB and Java
Meetup#2: Building responsive Symbology & Suggest WebService
No sql Database
Master tuning
ログ収集プラットフォーム開発におけるElasticsearchの運用
Webinar - Macy’s: Why Your Database Decision Directly Impacts Customer Experi...
Ad

Recently uploaded (20)

PDF
Salesforce Agentforce AI Implementation.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
Cost to Outsource Software Development in 2025
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
17 Powerful Integrations Your Next-Gen MLM Software Needs
PDF
AutoCAD Professional Crack 2025 With License Key
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Nekopoi APK 2025 free lastest update
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
Salesforce Agentforce AI Implementation.pdf
Design an Analysis of Algorithms II-SECS-1021-03
iTop VPN Crack Latest Version Full Key 2025
Cost to Outsource Software Development in 2025
Advanced SystemCare Ultimate Crack + Portable (2025)
Internet Downloader Manager (IDM) Crack 6.42 Build 41
17 Powerful Integrations Your Next-Gen MLM Software Needs
AutoCAD Professional Crack 2025 With License Key
Weekly report ppt - harsh dattuprasad patel.pptx
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Oracle Fusion HCM Cloud Demo for Beginners
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Operating system designcfffgfgggggggvggggggggg
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Designing Intelligence for the Shop Floor.pdf
Nekopoi APK 2025 free lastest update
Computer Software and OS of computer science of grade 11.pptx
Wondershare Filmora 15 Crack With Activation Key [2025

Spring Camp 2016 - List query performance improvement using Couchbase