AOL experienced explosive growth and needed a new database that was both flexible and easy to deploy with little effort. They chose MongoDB. Due to the complexity of internal systems and the data, most of the migration process was spent building a new identity platform and adapters for legacy apps to talk to MongoDB. Systems were migrated in 4 phases to ensure that users were not impacted during the switch. Turning on dual reads/writes to both legacy databases and MongoDB also helped get production traffic into MongoDB during the process. Ultimately, the project was successful with the help of MongoDB support. Today, the team has 15 shards, with 60-70 GB per shard.
8. Approach
• Document-based data model – use MongoDB
• Migrate data
• Build adapter/interceptor layer
• Production testing with no impacts
9. Approach
• Audit of setup with MongoDB
• Tweak mongo settings, including driver, to
optimize for performance
• Leverage eventual consistency to overcome
transactional integrity loss
• Switch Identity to new data model using
MongoDB
17. Production Testing
• “Chaos Monkey” testing of MongoDB
• 4 Million requests/Minute (production load,
read to write ratio 99%)
• Test primary failover (graceful)
• Kill Primary
18. Production Testing
• Test secondary failure
• Shutdown all secondaries
• Manually shutdown interface on primary
• Performance benchmarking
19. Production Testing
• Performance very good, shard key reads ~2-
3ms
• Scatter-gather reads ~12ms
• Writes good as well, ~3-20ms
• Failovers 4-5 minutes
20. MongoDB Healthcheck
• Use dedicated machines for Config servers
• Place Config servers in different data centers
• Handle failover in application, if network
exception, fallback to secondary
• Set lower TCP keepalive values (5 minutes)
23. Deployment
• Version 2.4.9
• All 75 mongod’s on separate switches
• 2 x 12 Core CPUs, 192GB of RAM and internal
controller based RAID 10 Ext4 File Systems
• Using default chunk size (64MB)
24. Deployment
• Have dedicated slaves for backup (configured
as hidden members with priority 0). Backup
runs during 6-8am window
• Enable powerOf2Sizes for collections to
reduce fragmentation
• Balancer restricted to 4-6am daily
26. Document Model
• Entire data set must be in memory to meet
performance demands
• Document field names abbreviated, but
descriptive
• Don’t store default values (Legacy document is
80% defaults)
• Working hard to keep legacy artifacts out, but
always about trade-offs
27. UserIdentity Collection
• Core data model for Identity
• Heterogenous collection (some documents
are “aliases” which are pointers to primary
document)
• Index on user+namespace
• Shard key is guid (UUID Type 1, flipped –
node then time)
29. Relationship Collection
• Support all cardinalities
• Equivalent to RDBMS intersection table (guid
on each end of relationship)
• Use eventually consistent framework for non-atomic
writes
• Shard key is parent+child+type (parent lookup
is primary use case)
31. Legacy Collection
• Bridge collection to facilitate migration from
old data model to new
• Near-image of old data model but with some
refactoring (3 tables into 1 document)
• Once migration is complete, plan is to drop
this collection
• Defaults not stored, 1-2 character field names
33. Reservation Collection
• Namespace protection
• Enforce uniqueness of user/namespace from
application side because shard key for
UserIdentity collection is guid
• Shard key is username+namespace
37. Solution
• Developed eventually consistent framework
“synchronizer”
• Events sent to framework to validate, repair,
or finish
• Events retryable until success or ttl is expired
39. Solution
• Use Memcached to map non-shard key to
shard key (99% hit ratio for one mapping, 55%
for other)
• Use Memcached to map potentially expensive
intermediary results (88% hit ratio)
40. Problem
Querying lists of users required parallel
processing for performance -- increasing
connection requirements
41. Solution
Use $in operator to query lists of users rather
than looping through individual queries
42. Problem
At application startup a large number of
requests failed because of overhead in creating
mongos connections
43. Solution
Build into application a “warm-up” stage that
executes stock queries prior to going online and
taking traffic
44. Problem
During failovers or other slow periods,
application queues back up and recovery takes
too long
49. Solution
Use primaryPreferred for reads. Want the
freshest data (password for example), but still
want reads to work if no primary exists
50. Problem
Large number of connections to
mongos/mongod is extending the failover times
and nearing limits
51. Solution
• Application DAOs share connections to same
Mongo cluster
• Connection params initially set too high
• Set connectionsPerHost and
connectionMultiplier plus a buffer to cover
the fixed number of worker threads per
application (15/5 for 32 worker threads).
• Went from 15K connections to 2K connections
53. Benefits
• Unanticipated benefit was ability for all
eligible users to use the AOL client
• Easily added Identity extensions leveraging
the new data model
• Support for multiple namespaces made
building APIs for multi-tenancy
straightforward
• Model is positioned in such a way to make
vision for AOL Identity feasible
55. Lessons Learned
• Keep connections as low as possible
– Higher connection numbers increase failover
times
• Avoid scatter-gather reads (use cache if
possible to get to shard key)
• Keep data set in memory
• Fail fast on application side to lower recovery
time
57. Going forward
• Implement tagging to target secondaries
• Further reduction in scatter-gather reads
• Reduce failover window to as short as possible
• Contact: doug.haydon@teamaol.com
Editor's Notes
----- Meeting Notes (9/9/14 14:55) -----
brands.aol.com, fingerprint brand logo, stuck on bottom of master page, invert colors
----- Meeting Notes (9/9/14 14:55) -----
after challanges, how we overcame, what is our strategy to overcome -- approach -- why chose mongo, document based
----- Meeting Notes (9/9/14 14:55) -----
what did we learn from this? What did we change? 10gen audit
----- Meeting Notes (9/9/14 14:55) -----
what did we learn from this? What did we change? 10gen audit