QA
Senior LevelMongoDB & Mongoose

How do you build fault-tolerant Change Stream consumer microservices using resume tokens (resumeAfter)?

❓ Interview Prompt: Explain Change Stream resume tokens (_data), persisting tokens in Redis, and resuming streams with resumeAfter after crashes.

Change Stream event objects include a '_data' resume token. Microservices persist this token in Redis to resume streams seamlessly after process restarts.

Code Implementation Example

typescript
import { OrderModel } from './models/Order';

function resumeChangeStream(savedResumeToken: any) {
  const stream = OrderModel.watch([], {
    resumeAfter: savedResumeToken
  });
  stream.on('change', (event) => console.log('Resumed event:', event._id));
}
💡Resuming Change Streams from saved resume tokens using resumeAfter.
🎯 Interview Key Takeaway

Persist Change Stream resume tokens in Redis to build fault-tolerant microservice event consumers.

#resumeAfter#Resume Tokens#Change Streams#Senior
Back to all MongoDB & Mongoose Questions→

More MongoDB & Mongoose Interview Questions

Beginner LevelMongoDB & Mongoose

How does the MongoDB Aggregation Pipeline work? Explain $match, $group, $lookup, and $project.

Beginner LevelMongoDB & Mongoose

What is MongoDB and how does the BSON document data model work?

Beginner LevelMongoDB & Mongoose

What is the structure of a MongoDB ObjectId and how is it generated?