GithubHelp home page GithubHelp logo

wackyalien / flashsale Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codesssss/flashsale

0.0 0.0 0.0 17.08 MB

Flash Sale System AKA. seckill system

Java 62.49% HTML 35.63% JavaScript 1.87%

flashsale's Introduction

FlashSaleSystem

Project highlights

Distributed system scheme

From a single machine to a cluster, it is easy to scale horizontally simply by adding servers to cope with greater traffic and concurrency

System optimization

Browser cache/Nginx cache/page cache/object cache/RabbitMQ queue asynchronous ordering, reduce network traffic, reduce database pressure, improve the system's concurrent processing capability

In-depth microservice skills

SpringBoot/RabbitMQ/Redis/MySQL, based on the most popular Java microservices framework

The security policy

Graphic verification code, flow limiting and brush prevention, interface address hiding, various security mechanisms to reject the robot ticket brushing

Server design ideas

The bottleneck is the database's ability to handle requests. After a large number of requests are sent to the database, the database may time out or break down due to its limited processing capability. So the idea is to try to intercept requests upstream of the system.

  • For applications that read a lot (read inventory) and write a little (create order), use caching more (for inventory query operations through caching, reduce database operations)

  • Cache, application, database cluster, load balancing; Asynchronous message processing

  • The foreground can do some restrictions to the normal user's operation through JS, and cache some static resources with CDN and user browser

The overall architecture

architecture

The detailed guide to build such a system

Chap01: Integrate Mybatis and Redis

Chap02: MD5 encryption and globle exception handler

Chap03: Implement distributed session via redis

Chap04: Implement the flash sale function

Chap05: Using JMeter to pressure test

Chap06: Page cache and object cache

Chap07: Integrate rabbitMQ and optimize the interface

Chap08: Optimizing the flash sale system after integrated rabbitMQ

Chap09: Dynamic flash sale url, mathematical formula verification code and the interface current limiting

Chap10: Conclusion the project

Main questions

How to ensure thread safety and prevent oversold when inventory is deducted in Redis?

Redis has a decr() method that implements decrement and atomicity

How to limit traffic and prevent robot access?

This is done by interceptor, and we have a custom annotation that will mark a method, specify the number of times it is accessed per unit of time, and if it exceeds the requirement, it will be intercepted.

Interceptor is inherited HandlerInterceptorAdapter, rewriting is preHandle method, in this method, will visit frequency synchronization to Redis, there is the period of validity of the key/value pair. Finally, you need to configure the interceptor into the project, inheriting the WebMvcConfigurerAdapter and overriding the addInterceptors() method.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.