REST advocates web applications without client state on the server. The famous shopping cart example is translated to a resource which typically resides in a database.
I wonder if it is a good practise to use a database for that kind of data, since the database is already the bottleneck in many applications. Wouldn't it be better to use a stateful enterprise java bean instead? Application servers are designed with clustring in mind.
What are the advantages and disadvantages of the two approaches?
An application server provides access to the data for the client. It serves as an interface between the client and one or more database servers, which provides an additional level of security. It can also perform some of the query processing for the client, thus removing some of the load from the database server.
HTTP is a stateless protocol, which means that once a web server completes a client's request for a web page, the connection between the two goes away. In other words, there is no way for a server to recognize that a sequence of requests all originate from the same client.
Storing sessions on the application server will only work if:
Storing sessions in a central database and/or EJB will work if your clients are not guaranteed to always connect to the same application node in your cluster.
Another approach to consider is using a service such as memcached. This will work in either case.
In general:
Database
In-Memory (non-distributed stateful bean)
Your choice will be totally dependent on your application requirements and environment. All things being equal, I favor the database solution because of the load balancing and reliability benefits, but this can easily be overkill in many scenarios.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With