Day 6 – “Enterprise Application Architecture Patterns” – Session State

Time:2019-3-10

1. Stateless value:

Stateless servers can handle many users with very few objects. The more users in idle state, the more useful the stateless servers are.

2. Session state:

Relevance: Session state is only related to the current session. It exists in business transactions and is separate from other sessions and their business transactions.

The difference from recording data information is that the persistent data stored in the database for a long time when recording data is visible to all sessions, and the session state needs to be submitted as a record in the database.

The biggest problem: when dealing with isolation (simultaneous or associated operations)

You can’t treat all data in a session as session state

3. The method of storing session state:

1) Three ways to store session state:

Customer session state: Save data on the client side (url, cookie, hidden domain available on the web, etc.)

Applicable scenario: Session data is small and users often cancel sessions (e.g. B2C users close sites directly and disappear)

Problem: Security, Integrity

Server session state: In server memory, file system, a simple database table (with session identification number as key and serialized object as value)

Advantages: Easy direct access to session state

Database session state: Store on the server side (decompose data into multiple tables and domains)

Advantages: State persistence is not easy to lose

Problem: Poor isolation (need to isolate session data from recorded data)

The above three modes are not mutually exclusive and can be mixed. When using it, you also need to pay attention to: client crash, server death, network connection disconnection.

2) Session expansion:

Session migration: Allows a session to be transferred from one server to another, so that one server can process one request while the other servers process other requests

Advantages: Balanced servers

Disadvantage: It is difficult to find session state and support session migration.

Server affinity: All requests for a particular session can only be processed by one server

Disadvantage: When a client uses a proxy, a large amount of load may be concentrated on a server.