title: “SecKill Development Journey (I)” lang: en ref: seckill-development-journey-part-I permalink: /docs/seckill-development-journey-part-I/ excerpt: “an introduction of how to build seckill demo project step by step” last_modified_at: 2017-09-13T09:00:00+08:00 author: Yangyong Zheng tags: [seckill] redirect_from:
SecKill is a demo project that our ServiceComb team try to build a micro-service architecture from the perspective of domain-driven design (DDD).
SecKill idea comments from the Internet popular promotions, using coupons to obtain some discounts; because the number of coupons is limited, so we must provide a platform for everyone who wants to get it fair competition.
As a demo project, so we don't want make the SecKill too complicated; we just use the most primitive strategy - first come first get. It is quite simple if you want to implements other strategies by yourself.
Now let's analyze requirement in customer bounded context:
Let's go! what? you say this description is to simple? because they are no registration system, and promotion is how come, how to start? which coupon the customer request for? Is the discount all same? etc.
Actually, we are accustomed to thinking a lot at the beginning, so some larger system, the design stage may be a few months, but this time you can't consider too much, because we believe:
Then, we can follow the many principles of domain-driven design (DDD). The core task of the design process is identify entities, value objects, services and other elements, and further search aggregation; because our requirements are very simple, so it's easy find them out:
Now we can find the aggregation between them, separated two microservice, now we direct use MySQL database for shared data (although microservice recommend use independent storage for each, we can revisit it in the next iteration)
{: .align-center}
The source code at Github, Welcome to Watch and Star : )
We create two class “SecKillCommandService” and “SecKillPersistentRunner” to accept seckill request and persist seckill result, considering persistence is slow, we use BlockQueue temporary cache requests. another class “SecKillCommandRestController” act as Endpoint; ServiceComb support a variety of programming models and communication model, also well support Spring Boot, and easy deploy to Huawei cloud.
{: .align-center}
Query logic is relatively simple, because PromotionEvent is Value-Object, we use PromotionEvent records to get Coupon Value-Object, you can read the source code and understand this process.
As promotion is entity and seckill need it as preconditions, we need build and manage it in another domain, because it's not so urgent at current stage, we can use Spring injection autowire fix objects.
{: .align-center}
Finally, we use PostMan to check completed functions, Please ensure request body fill with JSON format, and set Content-Type to application/json:
{: .align-center}
{: .align-center}