How stateless server can keep session state on server side?
Asked Answered
O

1

5

I'me reading Marting Fowler's famous book Patterns of enterprise application architecture to systematize my knowledge.

I've read chapter Session and States and I a bit confused. In the first part of the chapter author recommend to use stateless server to avoid some sort of issues. Then author says that sometimes wee need to save some data on the server side - for example user cart in a internet shop. But to implement session with state we can use stateless server. Then author describes ways to save session state(client, server, database)

But after reading this chapter I don't understand what a stateless server is. How a server can be stateless if it keeps session state ?

Ophthalmoscope answered 27/9, 2019 at 13:25 Comment(1)
The server does not keep "session state". Application keeps its state that can include session information as well.Politic
C
6

Quora has a nice definition:

A stateless service is a service that does not store any data on the application server. It reads or writes data to the database, returns a value (or not), and after that, any information on the task itself is forgotten.

Meaning: it isn't that server itself that keeps the state data. It can put it into some database. It might then provide the client with some sort of token that the client can include in future calls. And that token enables other servers to retrieve the corresponding data from say, a database.

The key point is: sure, the information needs to be stored somewhere. But that somewhere isn't the server, but some infrastructure that all the stateless servers can get to.

Condor answered 27/9, 2019 at 13:49 Comment(2)
So keeping session state on a client or in the database(or any other external store) allows us to have stateless server?Ophthalmoscope
@Ophthalmoscope I think that is a valid conclusion. The point is: your "state data" needs to go somewhere. When you want to enable yourself to "switch" servers between requests of the same client, then they can't sit solely on that server. But also note: of course that comes at consequences. I see that more of a potential vision to work towards. Even when you have "stateless" servers, they might "cache" information, and for performance reasons, you might want the same client go to the "same" server somehow.Condor

© 2022 - 2024 — McMap. All rights reserved.