Planable is a collaborative tool for teams collaborating and planning marketing content in real-time and we use MongoDB as our main database. In this talk I will describe our journey of scaling our app to handle tens of thousands of active clients working in real-time, using various techniques.
21. Poll-and-diff
SERVER CSERVER BSERVER A
C1 C2 C3 C4 C5 C6 C7 C8
Simple approach and easy to understand
scaling characteristics
Updates come with delay
Does not scale well with many users and data
Works with complex queries and sort/skip
22. Poll-and-diff
SERVER CSERVER BSERVER A
C1 C2 C3 C4 C5 C6 C7 C8
Simple approach and easy to understand
scaling characteristics
Updates come with delay
Does not scale well with many users and data
Works with complex queries and sort/skip
24. Tailing the Oplog
SERVER CSERVER BSERVER A
C1 C2 C3 C4 C5 C6 C7 C8
Oplog
Works seamlessly on light loads
Updates come in real-time
Little additional load on the database
25. Tailing the Oplog
SERVER CSERVER BSERVER A
C1 C2 C3 C4 C5 C6 C7 C8
Oplog
Works seamlessly on light loads
Updates come in real-time
Little additional load on the database
Batch updates, inserts, deletes
overwhelms the server
Cannot scale servers horizontally
28. Redis Oplog
SERVER CSERVER BSERVER A
C1 C2 C3 C4 C5 C6 C7 C8
No additional load on MongoDB
Server receives less updates
More control on reactivity
29. Redis Oplog
No additional load on MongoDB
SERVER CSERVER BSERVER A
C1 C2 C3 C4 C5 C6 C7 C8
Server receives less updates
More control on reactivity
Increased latency
Additional point of failure
Additional system to scale, monitor, maintain
No reactivity on external database operations
30. Change Streams
SERVER CSERVER BSERVER A
C1 C2 C3 C4 C5 C6 C7 C8
Change Streams
const changeStream = db.Posts.watch({
fullDocument: ‘updateLookup'
});
changeStream.on('change', next => {
// process next document
// send update to client
});
3.6+
31. Change Streams
SERVER CSERVER BSERVER A
C1 C2 C3 C4 C5 C6 C7 C8
Change Streams
3.6+
Decreased load on servers
Use powerful aggregation pipelines
Single source of truth
Reliable, durable, resumable
Limited number of opened streams
Increased memory usage of MongoDB
32. Using Change streams in production
• Reduce the number of streams opened
• Watch only the “hot” collections
• Allocate more memory (RAM) to MongoDB
• Increase the poolSize when connecting to MongoDB
• Distribute the change streams to secondaries