Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FlashSale

An ecommerce platform as web application project.

Main Tech Stack

Frontend jQuery, Thymeleaf, Bootstrap
Backend SpringBoot, MyBatis
Middleware Redis, RabbitMQ
Database MySQL

Table of Contents

Introduction

Function Development

Login & Register

LoginRegister Flowchart

Distributed Session:

To support distribution, single session is no enough:

Distributed Session

With Nginx's load balancing, requests are distributed to different Tomcats according to time order.

Suppose a user signs in at Tomcat1, the information will be stored in Session on Tomcat1. Later another request from the same user is distributed to Tomcat2, where no info of this user has been stored in Session, then the user will have to sign in again, which produces a bad experience.

  • Why Redis: security and easy scaling out.

Other Details:

  1. Exception Handler:

    • SpringMVC allows entralized handle of Exceptions. In this project, I used @ControllerAdvice and @ExceptionHandler annotations to catch different types of exceptions and prompt messages.
  2. Password Encryption: Double-layer salted hash

    • Frontend encryption: to avoid password being sent as clear text.
    • Backend encryption: hash password again before storing into database, in case of data leakage during transmission.
  3. Password Update:

    • Similar roadmap as Login/Register, with UserController and UserService.
    • Delete cache in Redis after update password in database to ensure cache consistency.

Listing & Detail Pages

Listing   Detail

Some Details:

  1. Listing:

    • Iterative blocks with Thymeleaf for list of products.
  2. Deal Period Validation:

    • Backend: Initialize deal status and countdown variable based on current server's time when fetching sales data from database.
    • Frontend: Conditional function based on deal status and countdown function with timeout.

Purchase

Purchase

Stock Check & Update:

  1. Check on server:
    • Keep track of stock status flags (empty/not) on server to reduce communication with Redis; if status is empty, skip following steps.
  2. Check and update on Redis:
    • Pre-decrement stock on Redis to check if stock is enough; if not, add it back, update status on server, and skip following steps.
  3. Update on database:
    • Send message to queue and wait for processing, where OrderService will update product stock in database when creating new order.

Improvements & Load Tests

Key improvements during the development process:

  1. Caching pages and objects.
  2. Minimize #requests to Redis and database.
  3. Implement a message queue to improved spike handling through asynchronous communication.

Load Test Preparation & Settings

Prepared 1500 users and user tickets (see implementation in UserUtil) for purchasing load test.

config

thread settings

Load Test Result: before improvements

load test before improve

Load Test Result: after improvements

load test after improvement

  • As shown above, there has been significant increase in throughput and decrease in response time.

message queue

  • With message queue implemented, the system perfectly managed data spikes (marked as yellow) and maintained steady processing (marked as green) without crashing the database, ensuring that the data is persisted and handled.

Live Test Video

flashsale thumbnail

DevLog: Feature Updates

(In progress)

About

SpringBoot eCommerce platform

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages