| > Even when storing the cookies in a database like Postgres, they are fast enough because it's obviously indexed, and it's probably cached in many usage patterns. If you scale up high enough, it does matter. But beyond that, it is also about decoupling the server serving the content and the user database. To give you an example, using a traditional session cookie model, whenever my server gets a request, it has to look up the associated session info, and then possibly join multiple tables to see if a specific user for that specific session is authorized to access that content. There are going to be many joins involved. Even with good caching, it will still be a more complex operation. Even if not computationally complex, it will be logically complex. But when using a JWT, my server actually does not need ANY db access. It merely needs to verify the cryptographic validity of the included JWT header, which uses no IO. After that, it can safely trust any user metadata included in the JWT. So, if a user has paid for access to all premium content after 2018, you would just include a field for that in your JWT payload. Done. It depends of course on how your business data models work of course. But you can often put enough information in your JWT to cut out a lot of account processing logic. > JWT is solving a non-problem for most people. I think people are cargo culting JWTs. |
You don't need any db access with signed cookies either. Just stash your data in a signed cookie and you're done. Should you need more than 4k for session data, maybe it's time to rethink about what should be stored in the session and what should be stored in the db.