Seckill is a common marketing method for e-commerce websites.

  • Don’t bring the whole system down.
  • Do not display error data even if the system fails.
  • Try to be fair.

Implementation effect

  • Before the start of the second kill, the snap button indicates that the activity has not started.
  • The snap button can be clicked to place an order when the seconds kill starts.
  • After the SEC kill is over, the button becomes the SEC kill is over.

Technology research

  • The impact of the large volume of traffic in a short period of time on the existing website business.

    Second kill is a website marketing an additional activity, short time, large concurrency.

    If the application is deployed together with the existing application, the existing service will be impacted. If the application is not deployed properly, the entire website may be paralyzed.

  • High concurrency creates a high load on the server database.

    Users refresh their browsers to ensure that they do not miss the event before it starts.

    Frequent access to programs and databases can put a load on application servers and database servers.

  • The problem with network bandwidth was many times higher than usual.

    If the size of the seckill page is 200K and the maximum number of concurrent requests is 10000, the required network and server bandwidth is 2G (200K x 10000).

    This network bandwidth is added because of seckill activity, which exceeds the bandwidth normally used by the site.

  • Avoid ordering directly.

    The rules of the game is to kill seconds to start the purchase of goods, before this time point, can only browse information can not order.

    And the order page is also a common URL, if you get this URL, do not have to wait until the second kill can be ordered.

Coping strategies

  • The system is deployed independently

    In order to avoid the impact of a large number of visits in a short period of time on the existing website business, you can deploy the seckill system independently.

    You can also use a separate domain name if you want to, which is completely isolated from the site.

    Even if the seckill system crashes, it will not affect the site.

  • Seconds kill product page static

    The product description, parameters, details, all written to a static page, without the logical processing of the program, without access to the database.

    You don’t have to deploy dynamic servers and database servers.

  • Lease the network bandwidth for the kill activity

    The new bandwidth must be purchased or leased from the carrier.

    In order to reduce the pressure on the server, it is necessary to cache the pages of seconds killing products in THE CDN, and the CDN server also needs to temporarily rent bandwidth.

  • Dynamically generate random order page URL

    In order to avoid the user to directly access the single URL, the URL needs to be dynamic, with random number as the parameter, can only be generated at the beginning of the second kill.

Architecture design

  • How to control the availability/deactivation of the snap button on the page.

    The buy button only lights up when the seckill starts, and is gray before that, indicating that the activity has not started.

    If the page is dynamically generated and the server is requested each time it is refreshed, this can cause a load on the server side.

    If the page is static, it can be cached on a CDN, a reverse proxy server, or even the user’s browser.

    But in this case, when the seckill starts, the user refreshes the page and does not request the application server at all.

    Solution:

    With JS scripting control, reference a JS file in the page (the file is very small), but the file is not cached.

    The JS function is to contain the kill start flag, modify the style, generate the order page URL and random parameters.

    The JS file is not cached as follows: xxx.js? V = random number.

    There will be a server for monitoring (scheduled depositioning) :

    Push the file when the seckill activity starts.

    When the seckill activity ends, push the file, mark the end mark, modify the style.

    The diagram below.




Brief introduction to the architecture design of seckill system -1

  • How to only allow the first order submitted into the order system.

    Since there is only one user for the goods, it is necessary to pre-check the order before submitting the order.

    If an order has been submitted successfully, the activity is complete and the end of seckilling page is displayed.

    In fact, there can only be one order number. To reduce the load on the order page server, the entry to the order page can be controlled.

    Only a few users can enter the order page, others directly enter the end of the second kill page.

    (Pre-check logic) Check the number of order requests processed by the machine:

    If the number of entries exceeds 10, the page is returned to the user.

    If there are no more than 10 items, the user can enter the page for filling in the order and confirming the order.

    Check the number of submitted orders globally:

    The total number of kill items has been exceeded, return to the end of kill page.

    Does not exceed the total number of seconds to kill goods, submitted to the sub-order system.

    The diagram below.




Brief introduction to the architecture design of seckill system -2

  • The operation of reducing inventory

    Take inventory reduction (good user experience)

    Payment reduction inventory

Placing an order is as simple as possible, the purchase data is 1 and not edgeable, the shipping address and payment method is empty or user default, allowing the order to be modified after submission.

The article draws on the book “Technical architecture of large Web sites”.

Thanks ~