Event Batching & Queuing
MentiQ Analytics uses an intelligent event queuing and batching system to optimize network requests, handle failures gracefully, and ensure reliable event delivery even in poor network conditions.Overview
Instead of sending every event immediately, MentiQ queues events locally and sends them in batches. This approach:- Reduces network overhead - Fewer HTTP requests
- Improves performance - Non-blocking event tracking
- Handles offline scenarios - Events queued until connection restored
- Provides retry logic - Automatic retry with exponential backoff
- Prevents data loss - Events stored until successfully sent
How It Works
1
Event Creation
When you call
track(), page(), or other tracking methods, events are created and added to an in-memory queue.2
Queue Storage
Events are stored as
QueuedEvent objects with metadata:3
Automatic Flushing
Events are automatically sent when either:
- Queue reaches
batchSize(default: 20 events) flushIntervaltimer expires (default: 10 seconds)
4
Batch Processing
Events are split into batches and sent to the backend endpoint:
5
Retry on Failure
If batch fails, events are re-queued with exponential backoff:
- 1st retry: Wait 1 second (retryDelay)
- 2nd retry: Wait 2 seconds (retryDelay × 2)
- 3rd retry: Wait 4 seconds (retryDelay × 4)
- After 3 attempts: Events discarded (configurable)
Configuration Options
Batch Size
Number of events to accumulate before sending:When to adjust batch size
When to adjust batch size
Increase batch size (30-50) for:
- High-traffic applications
- Reducing network requests
- Cost optimization
- Real-time analytics requirements
- Low-traffic applications
- Testing and development
Flush Interval
Maximum time to wait before sending queued events:Events are sent when either batch size is reached or flush interval expires, whichever comes first.
Max Queue Size
Maximum number of events to keep in queue:Retry Configuration
Control retry behavior for failed requests:- Attempt 1:
retryDelay × 2^0 = 1000ms - Attempt 2:
retryDelay × 2^1 = 2000ms - Attempt 3:
retryDelay × 2^2 = 4000ms
Manual Flushing
You can manually trigger event sending:Immediate Flush
Flush on Unload
Automatically flush when user leaves the page:Queue Management
Check Queue Size
Monitor how many events are queued:Clear Queue
Remove all queued events (use with caution):Backend Batch Endpoint
Events are sent to the batch endpoint in this format:Request Format
Response Format
Success (200 OK):Event Transformation
Before sending, events are transformed from the internal format to backend-compatible format:Internal Event Format
Backend Event Format
Event Type Mapping
The SDK automatically maps event types:Performance Optimization
Recommended Settings by Traffic Volume
- High Traffic (>10k events/day)
- Medium Traffic (1k-10k events/day)
- Low Traffic (<1k events/day)
- Real-Time Analytics
Flush on Critical Events
For important events that must be sent immediately:Debugging
Enable debug mode to see batching behavior:Error Handling
The SDK handles errors gracefully:Network Failures
API Errors
Best Practices
Configure appropriate batch sizes based on your traffic volume
Flush before navigation to prevent event loss
Monitor queue size in high-traffic applications
Use manual flush sparingly to avoid performance impact
Enable debug mode during development to understand behavior
Handle flush promises for critical events
Next Steps
TypeScript Types
Learn about QueuedEvent and batching types
Privacy Compliance
Implement privacy-safe event tracking