Company
Date Published
Author
Colin Sidoti
Word count
941
Language
English
Hacker News points
None

Summary

Debates about whether session authentication should be stateful or stateless often focus on the trade-off between security and speed. Stateful authentication, which uses a database to track active sessions, is considered more secure because it allows for instant session revocation if a threat is detected. Conversely, stateless authentication, which relies on cryptographically signed tokens like JWTs, is faster due to its minimal database interaction, offering rapid verification under 1 millisecond. To combine the advantages of both methods, a hybrid approach can be used, where stateless tokens have short expiration times and are periodically refreshed by querying the database to ensure the session remains active. This hybrid model allows for revocation within a brief timeframe, while maintaining the speed benefits of stateless authentication. Clerk has implemented this approach, setting tokens to expire every 60 seconds and refreshing them asynchronously, ensuring that the system remains both quick and secure.