Back to Editorial

Engineering8 min read
USSD Session Management Explained: Handling Statelessness
Asterisks Engineering
Core Team ·

The Challenge of Statelessness
USSD is a session-oriented protocol built on a stateless HTTP foundation. Every time a user types a number, your server receives a brand new request. Without proper session management, your app has no "memory."
Using Session IDs
Telco gateways provide a SessionId. This is your primary key. You must use this ID to look up the user's current state (e.g., "they are on page 3 of the registration flow").
Persistence Strategies
- In-Memory (Redis): Fastest, but sessions are lost if the cache clears.
- Database (PostgreSQL/MongoDB): Reliable, but adds latency.
- Asterisks Managed State: Our engine handles this automatically, using a tiered caching strategy to ensure sub-100ms response times.
Handling Timeouts
USSD sessions typically timeout after 20-30 seconds of inactivity. Your session management system must:
- Detect expired sessions.
- Clean up resources.
- Decide whether to let the user "resume" or start over.
Understanding session state is what separates a basic menu from a serious USSD application.
Topics
- USSD
- Session Management
- State Management
- Engineering
- Redis

