Backend Development 9 min read

Implementation Details of a Simple Seckill (Flash Sale) System Using SpringBoot

This article presents a step‑by‑step technical walkthrough of a SpringBoot‑based Seckill project, covering password MD5 hashing, distributed session management, unified exception handling, page and object caching, static page generation, memory flag with Redis pre‑decrement and RabbitMQ async processing, oversell prevention, and API rate limiting, followed by a visual demonstration of the system’s UI and source code download.

Architect's Guide
Architect's Guide
Architect's Guide
Implementation Details of a Simple Seckill (Flash Sale) System Using SpringBoot

1. Simple Seckill Project Overview

The project is built on SpringBoot and implements core features such as login, product list, product details, flash‑sale (seckill) purchase, and order details, incorporating asynchronous order processing, hotspot data caching, and oversell prevention techniques.

Key backend technologies include distributed session management, Redis pre‑decrement of inventory to reduce database load, and RabbitMQ for asynchronous order handling, as well as client‑side polling and interface rate limiting.

Development Stack

Backend: SpringBoot, MyBatis, MySQL, RabbitMQ, Redis

Frontend: HTML, jQuery, Thymeleaf

2. Implementation Details

1) Double MD5 Password Encryption

First MD5 protects the password during network transmission; the second MD5 protects the password in case the database is compromised.

2) Distributed Session Management

After successful authentication, a UUID token is generated, stored in Redis as token → userObject , and also placed in a cookie to maintain session state across requests.

3) Unified Exception Handling

All exceptions are intercepted via a custom interceptor and processed using @ControllerAdvice + @ExceptionHandler to return consistent error responses.

4) Page Cache + Object Cache

Rendered HTML pages are cached in Redis for fast retrieval, while hot objects such as user, product, and order data are also cached to reduce database queries.

5) Page Staticization

AJAX is used for asynchronous data fetching; the first request caches both page and data in the browser, enabling subsequent loads to be served from the client cache.

6) Memory Flag + Redis Pre‑decrement + RabbitMQ Async Processing

The system initializes a Map localOverMap at startup to mark sold‑out items, uses Redis DECR to pre‑decrement stock, and pushes successful purchase messages to RabbitMQ for asynchronous order creation.

private Map
localOverMap = new HashMap<>();
boolean over = localOverMap.get(goodsId);
if (over) {
    return Result.error(CodeMsg.MIAO_SHA_OVER);
}
long stock = redisService.decr(GoodsKey.getSeckillGoodsStock, "" + goodsId);
if (stock < 0) {
    localOverMap.put(goodsId, true);
    return Result.error(CodeMsg.MIAO_SHA_OVER);
}
SeckillOrder order = orderService.getOrderByUserIdGoodsId(user.getId(), goodsId);
if (order != null) {
    return Result.error(CodeMsg.REPEATE_MIAOSHA);
}
SeckillMessage sm = new SeckillMessage();
sm.setUser(user);
sm.setGoodsId(goodsId);
sender.sendSeckillMessage(sm);

7) Solving Oversell

Two strategies are used: (1) an UPDATE statement that decrements stock only when stock_count > 0 , and (2) a unique index on (user_id, goods_id) to prevent duplicate purchases. Optimistic locking with a version column is also applied for retry on conflict.

update seckill_goods set stock_count = stock_count-1 where goods_id = #{goodsId} and stock_count > 0

8) Interface Rate Limiting

A custom @AccessLimit annotation limits each user to a maximum of 5 requests within 5 seconds and requires login status.

@AccessLimit(seconds=5, maxCount=5, needLogin=true)
@RequestMapping(value="/path", method=RequestMethod.GET)
@ResponseBody
public Result
getSeckillPath(User user, @RequestParam("goodsId") long goodsId) {
    if (user == null) {
        return Result.error(CodeMsg.USER_NO_LOGIN);
    }
    String path = seckillService.createPath(user, goodsId);
    return Result.success(path);
}

3. Effect Demonstration

1) Project Code Structure

Visual diagram of the module layout (image omitted).

2) Login Page

Sample credentials: account 15898989898 , password 123456 .

3) Seckill Product List

Screenshot of the product listing page (image omitted).

4) Product Details

Screenshot of the product detail view (image omitted).

5) Order Details After Purchase

Screenshot showing order information after a successful seckill (images omitted).

6) Source Code Download

Project source can be cloned from https://gitee.com/jike11231/sec-kill-product .

backend developmentRedisRabbitMQSpringBootseckill
Architect's Guide
Written by

Architect's Guide

Dedicated to sharing programmer-architect skills—Java backend, system, microservice, and distributed architectures—to help you become a senior architect.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.