Notes from the guest forum

project description:


        ​​​​A forum project with complete basic functions. The main functions of the project are: registration method based on email activation, password storage method based on MD5 encryption and salting, login function adds random verification code verification, realizes login status check, and displays different interfaces and functions for tourists and logged-in users. Support users to upload avatars, and implement functions such as publishing posts, commenting on posts, sending private messages, and filtering sensitive words. Implemented the like, follow and system notification functions.

(Main work) Project role:


Development of various back-end modules; design of database tables

Specific implementation of core functions:

1. By issuing login credentials to logged-in users, recording the login status of logged-in users, and using interceptors to check login status, the defects caused by http's statelessness are solved and resources that require specific login are protected.
2. Use Redis as a local cache for frequently accessed data, such as basic user information, to improve server performance.

3. Use the collection data type of Redis to solve the functions of dislike and follow each other, adopt transaction management to ensure the accuracy of the data, and adopt the "update the database first, then delete the cache" strategy to ensure the consistency of the database and cached data.
4. Use Kafka as the message queue. After the user is liked, commented, and followed, it is put into the asynchronous queue and pushed to the user in the form of system notification to decouple the system and cut peaks. .

Project gains:


1. Familiar with the operation process of developing projects under the Spring Boot framework
2. Familiar with the usage scenarios of Redis and the benefits of applying Redis.
3. Understand the basic use of Kafka as a message queue and understand the role of Kafka in the project

technology stack

Spring Boot、SSM、Redis、Kafka、ElasticSearch、Spring Security、Quatz、Caffeine

Project Highlights

1. The project is built on the Spring Boot+SSM framework, and uniformly implements status management, transaction management, and exception handling;

2. Use Redis to implement the like and follow functions, which can reach 5000TPS on a single machine;

3. Use Kafka to implement asynchronous in-site notifications, with a single machine up to 7000TPS;

4. Use ElasticSearch to implement the full-text search function, which can accurately match search results and highlight keywords;

5. Use Caffeine+Redis to implement two-level caching and optimize access to popular posts. A single machine can reach 8000QPS.

6. Use Spring Security to implement permission control and realize multi-role and URL-level permission management;

7. Use HyperLogLog and Bitmap to realize the statistical functions of UV and DAU respectively. One million user data only requires *M memory space;

8. Use Quartz to implement task scheduling functions, and implement functions such as regularly calculating post scores and regularly cleaning junk files;

9. Use Actuator to monitor the applied beans, cache, logs, paths and other dimensions, and monitor the database connection through customized endpoints.

How to record the user’s login status?

        After the user logs in, a ticket will be created for the user, and a cookie will be returned to the browser. The next time the user visits, the browser will bring the cookie (ticket), and the server can determine the user's login status based on the cookie. , and query the user ID through the ticket. Through the user ID, you can know the specific information of the current user. Put the user into the model, and then render it by the template engine and return HTML to the client browser. Displaying the user's login information is required for all requests, so this business logic is implemented by the interceptor! !

What are cookies? What is the difference between it and session? The relationship between cookies and sessions 

Why use Redis

1. Redis is a NoSQL database based on key-value pairs. It supports a variety of data structures: strings, hashes, lists, sets, sorted sets )wait

2. Redis stores all data in memory, so its read and write performance is amazing. At the same time, Redis can also save the data in the memory to the hard disk in the form of snapshots or logs to ensure data security.

3. Cache, ranking list (hot posts), counter, social network (number of likes), message queue, etc.

How to optimize the login module

1. Use Redis to store verification codes
                Verification codes require frequent access and refresh, which have higher performance requirements
                Verification codes do not need to be saved permanently , usually fails after a short period of time.
                During distributed deployment, there is a problem of Session sharing

2. Use Redis to store login credentials
                When processing each request, the user's login credentials must be queried, and the frequency of access is very high.

3. Use Redis to cache user information
                When processing each request, user information must be queried based on the credentials, and the frequency of access is very high.

1. Steps to use Redis to store verification codes

        When the user clicks to refresh the verification code, the server first sets a random string (kaptchaOwner) for the current visitor who needs to log in to identify the current visitor, and then stores the random string into the cookie and returns it to The browser, and then the server-side redis saves key: random string, value: verification code.

        Then the user enters the user name, password, and verification code. When clicking to log in again, the server will get the kaptchaOwner from the cookie. Through it, the correct verification code can be obtained from Redis, and then verified with the user input. Compare the codes to see if they are consistent.

How to use kafka for system notification?

Guess you like

Origin blog.csdn.net/qq_45874683/article/details/133921177