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
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
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
}
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