1. Single sign-on
1.1 What is Single Sign-on
Single sign-on (SSO) : Multiple login Prerequisites: Single sign-on (SSO) is used in a distributed system
1.2 the Demo
Visit to the zoo:
- If you go directly to the zoo, you will be stopped directly, and if you don’t, you will go to the ticket office to buy a ticket
- Login = buy tickets
- I’m going to buy a ticket [hold a ticket, get in]
- Token = tickets
- We can visit with a ticket
2. The shopping cart
2.1 Definition of shopping cart
- The relationship between the shopping cart and the user
- A user must correspond to a shopping cart (no matter how many items a user buys, they are stored in their own shopping cart)
- Single sign-on must precede the shopping cart
- What are the operations related to shopping carts
- Add shopping cart
- The user is not logged in
- Where do I add it? Where do I save data without logging in
- Redis — Jingdong
- Cookie — your own development can be used
- If cookies are disabled, they can be stored in LocalStorege
- Where do I add it? Where do I save data without logging in
- User Login Status
- Redis cache (fast read and write)
- Hash: hset store (key, field, value)
- Key : user : userID cart
- Hset(Key , skuID , value)
- Hash: hset store (key, field, value)
- It is stored in the database (Oracle, mysql) to ensure data security
- Redis cache (fast read and write)
- The user is not logged in
- Display shopping cart
- Unlogged status display
- Get the data display directly from the cookie
- Login Status Display
- Once the user is logged in: the shopping cart data must be displayed in the database (Redis) + Cookie
- There are three records in the Cookie
- There are five in Redis
- There should have been eight
- Once the user is logged in: the shopping cart data must be displayed in the database (Redis) + Cookie
- Unlogged status display
- Add shopping cart
3. Message queues
3.1 background
How is high concurrency handled in distributed systems
- In a high-concurrency environment, requests that are sent by the user cannot be processed synchronously, resulting in request blocking
- Too many connections errors are triggered when a large number of Insert,update and other requests are sent to the MySQL database at the same time. The solution is asynchronous communication using message queues
- asynchronous
- parallel
- Line up
- Usage Scenarios:
- Disadvantages of message queues:
- Message uncertainty: delay queue, polling technology to solve the problem