SlideShare a Scribd company logo
1 of 18
Retail Profitability, Improved
Small Blobs and Big Logs
Different use cases for MongoDB at ShopperTrak
About Us
Retail Profitability, Improved
■Largest retail foot traffic counting and analytics
company in the world.
About Us
Retail Profitability, Improved
=
=
Some Stats
■20 year old company
■50,000 plus retail locations
■100+ countries
■20 billion people counted every year
Retail Profitability, Improved
Who IsThis Guy
■Former co-founder/CTO of a video analytics company
acquired by ShopperTrak in late 2012
■Using MongoDB since 2009 (before auto-sharding
even)
■Currently working across product and technology to
bring new ideas to life at ShopperTrak, primarily in
video and Bluetooth Low-Energy
Retail Profitability, Improved
Hash Check -- Guy talking
should look somewhat like
this
OurTechnology Stack
■Java/Groovy with a bit of Node.js
■Increasingly more Javascript single page apps in
Angular and React
■Data Layer
▼Oracle, and lots of it still
▼MySQL from acquisitions (AWS RDS)
▼Hazelcast for in-memory storage
▼S3 for video and file storage
▼Redshift for data warehousing
▼And of course MongoDB (6 nodes, 2 shards)
Retail Profitability, Improved
You’re welcome Larry
4 Distinct Uses at ShopperTrak
Application Uses (major)
▼Small Blobs
V Small number of documents (rows)
V Each document has a rich object
structure
▼Big Logs
V Lots (billions) of documents
V Each document is very narrow
Generic Cross Application Uses
(minor)
▼Distributed Queue
V Many applications sharing a work
queue
▼Distributed Lock
V Many applications being able to lock a
resource globally
Retail Profitability, Improved
Cross Application Uses – Distributed Queue
■Sounds a bit crazy and “off label” but works well and
we’re not alone. [1]
■What
▼Tasks/Events are generated into a global distributed log
▼Isolated applications can take jobs for processing
Retail Profitability, Improved
App 1 App 2 Event App
Mongo DB
appendfindAndModify
[1] https://blog.serverdensity.com/queueing-mongodb-using-mongodb/ , https://github.com/gaillard/mongo-queue-java ,
https://blog.serverdensity.com/replacing-rabbitmq-with-mongodb/, http://www.ibm.com/developerworks/library/os-mongodb-work-queues/
Cross Application Uses – Distributed Queue
■Why
▼findAndModify allows for atomic task ‘check-out’
Like SELECT … FOR UPDATE in SQL but without transactional
overhead
▼Durable structure
▼Infrastructure already exists and well understood
■How
▼Query by queue name, timestamp, completed
▼Ensure size of document doesn’t change on update
Retail Profitability, Improved
Cross Application Uses – Distributed Queue
Retail Profitability, Improved
collection.findAndModify(
[
queue: name,
'meta.ttl': ['$lt': now],
'meta.completed': 0l
],
[
'$set': [
'meta.worker': worker,
'meta.ttl': now + timeToLive
]
]
)
Cross Application Uses – Distributed Locks
Retail Profitability, Improved
■Needed a persistent globally distributed lock
■What
▼Distributed isolated systems atomically lock resources
▼Moving toward fronting this system with in-memory
Hazelcast cluster
■Why
▼Mongo provides us an atomic operation that is also
persisted
▼Performance is fast as long as lock lookup is indexed
■How
▼findAndModify on lock name, lock time < expiration
▼TTL on lock to automatically remove if processes die
Small Blobs
Retail Profitability, Improved
Physical people counting device
(e.g. orbit)
TCE (site)
THUB (camera hub)
TPPL_CNTR (people
counting device)
A site, this is the starting point for
both equipment and reporting
Mainly a remnant of mall setups. New
orbits do not have a physical hub.
TZN (zone)
A zone that collects together a logical
collection of traffic monitoring points
TTMP (monitoring
point)
A door can have 1 or more orbits
monitoring it through a traffic monitoring
point
REPORTINGPHYSICAL DEVICES
TCE (org)
~ 85,000 documents
Small Blobs
Retail Profitability, Improved
{
"_id" : NumberLong(81086),
"external" : {
"tz" : "America/New_York",
"loc" : [-75.160977, 39.948711],
"level" : "street",
"format_addr" : "1206 Walnut Street …"
},
"siteId" : NumberLong(81086),
"name" : "81086 OB Walnut",
"timezone" : "America/New_York",
…
"type" : "Retailer",
"org" : {
"id" : NumberLong(5521),
"name" : "Orange Branded LLC - ATT"
},
"search" : "5521 ORANGE BRANDED …",
"addrs" : [{
"type" : "Main",
"addr1" : "1206 Walnut St",
…
}],
"hubs" : [{
"id" : NumberLong(110240),
"devs" : [{
"id" : NumberLong(398884)
"endDt" : ISODate("9999-12-31T06:00:00Z"),
}]
}],
…
"zones" : [{
"id" : NumberLong(362337),
"type" : "TotalProp",
"tmps" : [{
"id" : NumberLong(404269),
"name" : "Standard",
"devs" : [NumberLong(398884),
NumberLong(398885) ]
}]
}],
"updateDate" : ISODate("2014-10-30T21:38:33.33Z")
}
http://stackoverflow.com/q/17268770/311525
Set Operations Before and After
Retail Profitability, Improved
db.colors.aggregate([
{'$unwind' : "$left"},
{'$unwind' : "$right"},
{'$project': {
value:"$left",same:{$cond:
[{$eq:["$left","$right"]}, 1, 0]}
}
},
{'$group' : {
_id: {id:'$_id', val:'$value'},
doesMatch:{$max:"$same"}
}
},
{'$match':{doesMatch:1}},
]);
db.colors.aggregate([
{'$project': {
int:{$setIntersection:["$left","$right"]}
}
}
]);
Union and set difference even longer.
One example 46 lines long to prepare
for union.
db.colors.insert({
_id: 1,
left : ['red', 'green'],
right : ['green', 'blue']
});
Without Set Operations With Set Operations
Big Logs
■Many very small documents
■Names are 1 character because Mongo uses storage
space for field names in every document.
Retail Profitability, Improved
> 7 billion documents/yr
{
“s" : 81086,
“i" : 3,
“o" : 4,
“t" : ISODate(“2014-12-31T06:00:00Z")
“d" : 300
}
Map Reduce vs Aggregation
Retail Profitability, Improved
db.salescanonicaldata.mapReduce(
function () {
var key= {rawFileId:this.rawFileId,
internalSiteId:this.internalSiteId,
siteZoneId:this.siteZoneId,
categoryId:this.categoryId,
hourEndTS:this.hourEndTS};
var value = {transactionId: this.transactionId,
totalTransactions:this.totalTransactions,
totalItems:this.totalItems,
totalSalesAmount:this.totalSalesAmount};
emit(key,value);
},
function(key, values) {
var result={totalTransactions: 0, totalItems: 0,
totalSalesAmount: 0.0};
var uniqueTransactionIdMap = [];
for(var i = 0; i<values.length; i++) {
if(uniqueTransactionIdMap.indexOf(values[i].transactionId)==-1){
// Count Distinct TransactionIds only once
uniqueTransactionIdMap.push(values[i].transactionId);
result.totalTransactions+=values[i].totalTransactions;
}
result.totalItems+=values[i].totalItems;
result.totalSalesAmount+=values[i].totalSalesAmount;
}
result.createdTS = new Date();
return result;
},
{out: 'mr_out'}
)
db.runCommand({
aggregate: 'salescanonicaldata',
allowDiskUse: true,
cursor: { },
pipeline: [
{$group: {_id: {key: {rawFileId: '$rawFileId',
internalSiteId: '$internalSiteId',
siteZoneId: '$siteZoneId',
categoryId: '$categoryId',
hourEndTS: '$hourEndTS'},
transactionId: '$transactionId'},
totalTransactions: {$first: '$totalTransactions'},
totalItems: {$sum: '$totalItems'},
totalSalesAmount: {$sum: '$totalSalesAmount'},
}},
{$group: {_id: '$_id.key',
totalTransactions: {$sum: '$totalTransactions'},
totalItems: {$sum: '$totalItems'},
totalSalesAmount: {$sum: '$totalSalesAmount'},
}},
{$project: {_id: 1,
totalTransactions: 1,
totalItems:1,
totalSalesAmount:1,
createdTS: {$literal: ISODate()},
}},
{$out: 'pa_out'},
],
})
> 20 x
Faster
Experience Moving Data
Issues
■Organizationally many people tied to Oracle
■Lots of business logic coded in PL/SQL
Solutions
■Move toward microservice architecture
■Schema in NoSQL still matters, get the model right
■Process in parallel to ensure business consistency and
prove value at scale
Retail Profitability, Improved
QUESTIONS?
Retail Profitability, Improved

More Related Content

Similar to How ShopperTrak Is Using MongoDB

MongoDB@sfr.fr
MongoDB@sfr.frMongoDB@sfr.fr
MongoDB@sfr.fr
beboutou
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016
Mir Mahmood
 

Similar to How ShopperTrak Is Using MongoDB (20)

Tugdual Grall - From SQL to NoSQL in less than 40 min - NoSQL matters Paris 2015
Tugdual Grall - From SQL to NoSQL in less than 40 min - NoSQL matters Paris 2015Tugdual Grall - From SQL to NoSQL in less than 40 min - NoSQL matters Paris 2015
Tugdual Grall - From SQL to NoSQL in less than 40 min - NoSQL matters Paris 2015
 
SQL vs NoSQL, an experiment with MongoDB
SQL vs NoSQL, an experiment with MongoDBSQL vs NoSQL, an experiment with MongoDB
SQL vs NoSQL, an experiment with MongoDB
 
Webinar: Scaling MongoDB
Webinar: Scaling MongoDBWebinar: Scaling MongoDB
Webinar: Scaling MongoDB
 
Webinar: How Banks Use MongoDB as a Tick Database
Webinar: How Banks Use MongoDB as a Tick DatabaseWebinar: How Banks Use MongoDB as a Tick Database
Webinar: How Banks Use MongoDB as a Tick Database
 
Columnstore improvements in SQL Server 2016
Columnstore improvements in SQL Server 2016Columnstore improvements in SQL Server 2016
Columnstore improvements in SQL Server 2016
 
MongoDB@sfr.fr
MongoDB@sfr.frMongoDB@sfr.fr
MongoDB@sfr.fr
 
Sam Dillard [InfluxData] | Performance Optimization in InfluxDB | InfluxDays...
Sam Dillard [InfluxData] | Performance Optimization in InfluxDB  | InfluxDays...Sam Dillard [InfluxData] | Performance Optimization in InfluxDB  | InfluxDays...
Sam Dillard [InfluxData] | Performance Optimization in InfluxDB | InfluxDays...
 
MongoDB Evenings Houston: Implementing EDW Using MongoDB by Purvesh Patel, Ch...
MongoDB Evenings Houston: Implementing EDW Using MongoDB by Purvesh Patel, Ch...MongoDB Evenings Houston: Implementing EDW Using MongoDB by Purvesh Patel, Ch...
MongoDB Evenings Houston: Implementing EDW Using MongoDB by Purvesh Patel, Ch...
 
Confluent & MongoDB APAC Lunch & Learn
Confluent & MongoDB APAC Lunch & LearnConfluent & MongoDB APAC Lunch & Learn
Confluent & MongoDB APAC Lunch & Learn
 
Scaling MongoDB
Scaling MongoDBScaling MongoDB
Scaling MongoDB
 
Mondrian - Geo Mondrian
Mondrian - Geo MondrianMondrian - Geo Mondrian
Mondrian - Geo Mondrian
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016
 
Perchè potresti aver bisogno di un database NoSQL anche se non sei Google o F...
Perchè potresti aver bisogno di un database NoSQL anche se non sei Google o F...Perchè potresti aver bisogno di un database NoSQL anche se non sei Google o F...
Perchè potresti aver bisogno di un database NoSQL anche se non sei Google o F...
 
MongoDB.local Austin 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch A...
MongoDB.local Austin 2018:  Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch A...MongoDB.local Austin 2018:  Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch A...
MongoDB.local Austin 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch A...
 
ER/Studio and DB PowerStudio Launch Webinar: Big Data, Big Models, Big News!
ER/Studio and DB PowerStudio Launch Webinar: Big Data, Big Models, Big News! ER/Studio and DB PowerStudio Launch Webinar: Big Data, Big Models, Big News!
ER/Studio and DB PowerStudio Launch Webinar: Big Data, Big Models, Big News!
 
Altitude San Francisco 2018: Logging at the Edge
Altitude San Francisco 2018: Logging at the Edge Altitude San Francisco 2018: Logging at the Edge
Altitude San Francisco 2018: Logging at the Edge
 
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
 
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
 
Scio - A Scala API for Google Cloud Dataflow & Apache Beam
Scio - A Scala API for Google Cloud Dataflow & Apache BeamScio - A Scala API for Google Cloud Dataflow & Apache Beam
Scio - A Scala API for Google Cloud Dataflow & Apache Beam
 

More from MongoDB

More from MongoDB (20)

MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
 
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDBMongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
 

Recently uploaded

Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
amitlee9823
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
AroojKhan71
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
amitlee9823
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
amitlee9823
 

Recently uploaded (20)

Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 

How ShopperTrak Is Using MongoDB

  • 1. Retail Profitability, Improved Small Blobs and Big Logs Different use cases for MongoDB at ShopperTrak
  • 2. About Us Retail Profitability, Improved ■Largest retail foot traffic counting and analytics company in the world.
  • 4. Some Stats ■20 year old company ■50,000 plus retail locations ■100+ countries ■20 billion people counted every year Retail Profitability, Improved
  • 5. Who IsThis Guy ■Former co-founder/CTO of a video analytics company acquired by ShopperTrak in late 2012 ■Using MongoDB since 2009 (before auto-sharding even) ■Currently working across product and technology to bring new ideas to life at ShopperTrak, primarily in video and Bluetooth Low-Energy Retail Profitability, Improved Hash Check -- Guy talking should look somewhat like this
  • 6. OurTechnology Stack ■Java/Groovy with a bit of Node.js ■Increasingly more Javascript single page apps in Angular and React ■Data Layer ▼Oracle, and lots of it still ▼MySQL from acquisitions (AWS RDS) ▼Hazelcast for in-memory storage ▼S3 for video and file storage ▼Redshift for data warehousing ▼And of course MongoDB (6 nodes, 2 shards) Retail Profitability, Improved You’re welcome Larry
  • 7. 4 Distinct Uses at ShopperTrak Application Uses (major) ▼Small Blobs V Small number of documents (rows) V Each document has a rich object structure ▼Big Logs V Lots (billions) of documents V Each document is very narrow Generic Cross Application Uses (minor) ▼Distributed Queue V Many applications sharing a work queue ▼Distributed Lock V Many applications being able to lock a resource globally Retail Profitability, Improved
  • 8. Cross Application Uses – Distributed Queue ■Sounds a bit crazy and “off label” but works well and we’re not alone. [1] ■What ▼Tasks/Events are generated into a global distributed log ▼Isolated applications can take jobs for processing Retail Profitability, Improved App 1 App 2 Event App Mongo DB appendfindAndModify [1] https://blog.serverdensity.com/queueing-mongodb-using-mongodb/ , https://github.com/gaillard/mongo-queue-java , https://blog.serverdensity.com/replacing-rabbitmq-with-mongodb/, http://www.ibm.com/developerworks/library/os-mongodb-work-queues/
  • 9. Cross Application Uses – Distributed Queue ■Why ▼findAndModify allows for atomic task ‘check-out’ Like SELECT … FOR UPDATE in SQL but without transactional overhead ▼Durable structure ▼Infrastructure already exists and well understood ■How ▼Query by queue name, timestamp, completed ▼Ensure size of document doesn’t change on update Retail Profitability, Improved
  • 10. Cross Application Uses – Distributed Queue Retail Profitability, Improved collection.findAndModify( [ queue: name, 'meta.ttl': ['$lt': now], 'meta.completed': 0l ], [ '$set': [ 'meta.worker': worker, 'meta.ttl': now + timeToLive ] ] )
  • 11. Cross Application Uses – Distributed Locks Retail Profitability, Improved ■Needed a persistent globally distributed lock ■What ▼Distributed isolated systems atomically lock resources ▼Moving toward fronting this system with in-memory Hazelcast cluster ■Why ▼Mongo provides us an atomic operation that is also persisted ▼Performance is fast as long as lock lookup is indexed ■How ▼findAndModify on lock name, lock time < expiration ▼TTL on lock to automatically remove if processes die
  • 12. Small Blobs Retail Profitability, Improved Physical people counting device (e.g. orbit) TCE (site) THUB (camera hub) TPPL_CNTR (people counting device) A site, this is the starting point for both equipment and reporting Mainly a remnant of mall setups. New orbits do not have a physical hub. TZN (zone) A zone that collects together a logical collection of traffic monitoring points TTMP (monitoring point) A door can have 1 or more orbits monitoring it through a traffic monitoring point REPORTINGPHYSICAL DEVICES TCE (org) ~ 85,000 documents
  • 13. Small Blobs Retail Profitability, Improved { "_id" : NumberLong(81086), "external" : { "tz" : "America/New_York", "loc" : [-75.160977, 39.948711], "level" : "street", "format_addr" : "1206 Walnut Street …" }, "siteId" : NumberLong(81086), "name" : "81086 OB Walnut", "timezone" : "America/New_York", … "type" : "Retailer", "org" : { "id" : NumberLong(5521), "name" : "Orange Branded LLC - ATT" }, "search" : "5521 ORANGE BRANDED …", "addrs" : [{ "type" : "Main", "addr1" : "1206 Walnut St", … }], "hubs" : [{ "id" : NumberLong(110240), "devs" : [{ "id" : NumberLong(398884) "endDt" : ISODate("9999-12-31T06:00:00Z"), }] }], … "zones" : [{ "id" : NumberLong(362337), "type" : "TotalProp", "tmps" : [{ "id" : NumberLong(404269), "name" : "Standard", "devs" : [NumberLong(398884), NumberLong(398885) ] }] }], "updateDate" : ISODate("2014-10-30T21:38:33.33Z") } http://stackoverflow.com/q/17268770/311525
  • 14. Set Operations Before and After Retail Profitability, Improved db.colors.aggregate([ {'$unwind' : "$left"}, {'$unwind' : "$right"}, {'$project': { value:"$left",same:{$cond: [{$eq:["$left","$right"]}, 1, 0]} } }, {'$group' : { _id: {id:'$_id', val:'$value'}, doesMatch:{$max:"$same"} } }, {'$match':{doesMatch:1}}, ]); db.colors.aggregate([ {'$project': { int:{$setIntersection:["$left","$right"]} } } ]); Union and set difference even longer. One example 46 lines long to prepare for union. db.colors.insert({ _id: 1, left : ['red', 'green'], right : ['green', 'blue'] }); Without Set Operations With Set Operations
  • 15. Big Logs ■Many very small documents ■Names are 1 character because Mongo uses storage space for field names in every document. Retail Profitability, Improved > 7 billion documents/yr { “s" : 81086, “i" : 3, “o" : 4, “t" : ISODate(“2014-12-31T06:00:00Z") “d" : 300 }
  • 16. Map Reduce vs Aggregation Retail Profitability, Improved db.salescanonicaldata.mapReduce( function () { var key= {rawFileId:this.rawFileId, internalSiteId:this.internalSiteId, siteZoneId:this.siteZoneId, categoryId:this.categoryId, hourEndTS:this.hourEndTS}; var value = {transactionId: this.transactionId, totalTransactions:this.totalTransactions, totalItems:this.totalItems, totalSalesAmount:this.totalSalesAmount}; emit(key,value); }, function(key, values) { var result={totalTransactions: 0, totalItems: 0, totalSalesAmount: 0.0}; var uniqueTransactionIdMap = []; for(var i = 0; i<values.length; i++) { if(uniqueTransactionIdMap.indexOf(values[i].transactionId)==-1){ // Count Distinct TransactionIds only once uniqueTransactionIdMap.push(values[i].transactionId); result.totalTransactions+=values[i].totalTransactions; } result.totalItems+=values[i].totalItems; result.totalSalesAmount+=values[i].totalSalesAmount; } result.createdTS = new Date(); return result; }, {out: 'mr_out'} ) db.runCommand({ aggregate: 'salescanonicaldata', allowDiskUse: true, cursor: { }, pipeline: [ {$group: {_id: {key: {rawFileId: '$rawFileId', internalSiteId: '$internalSiteId', siteZoneId: '$siteZoneId', categoryId: '$categoryId', hourEndTS: '$hourEndTS'}, transactionId: '$transactionId'}, totalTransactions: {$first: '$totalTransactions'}, totalItems: {$sum: '$totalItems'}, totalSalesAmount: {$sum: '$totalSalesAmount'}, }}, {$group: {_id: '$_id.key', totalTransactions: {$sum: '$totalTransactions'}, totalItems: {$sum: '$totalItems'}, totalSalesAmount: {$sum: '$totalSalesAmount'}, }}, {$project: {_id: 1, totalTransactions: 1, totalItems:1, totalSalesAmount:1, createdTS: {$literal: ISODate()}, }}, {$out: 'pa_out'}, ], }) > 20 x Faster
  • 17. Experience Moving Data Issues ■Organizationally many people tied to Oracle ■Lots of business logic coded in PL/SQL Solutions ■Move toward microservice architecture ■Schema in NoSQL still matters, get the model right ■Process in parallel to ensure business consistency and prove value at scale Retail Profitability, Improved