System design problem: how to design a business platform redeem system!

1, a Class widen the gap face questions

Now often encounter a kind of interview questions, the interviewer let you live to design a system in a business scenario, the system often has some difficulties in business or technology, mainly on you for many years down the accumulation of system design technical ability and the ability of thinking.

 

Many similar such system design issues, such as:

 

  • You design a spike system

  • You design a million users of IM message system support

  • You design a micro-channel system red

  • You design a business platform redeem system

 

These topics are themselves open proposition, there is no fixed answer. Encounter this problem, we must not panic, the key is in the field to clear thinking, reasonable, slowly analysis.

 

In this paper, one of the problems: design a business platform redeem systems to elaborate. This paper will detail pointed out at the time of system design which points to consider, to show you out a process such issues to think about.

 

 

2, description of business needs

Now assume that the interviewer to come out to redeem the relevant requirements of this system electronic business platform are as follows:

 

  1. Electronic business platform where users usually through the purchase of goods, sun single comment can continue to accumulate points

  2. After accumulating enough points, they can redeem electronic business platform of the page, choose to use their points to exchange some gifts

 

Demand actually so simple, so the interviewer said, given your thought process and implementation of this mechanism should be noted that in some places here for this business scenario.

 

 

3, thinking of business processes

How to think? First, the user purchase goods and non-stop sun single comment, will continue to earn points, it is not a required standings, designed to store each user points it?

 

Yes, this is necessarily a table, the table can be given the structure of the scene below.

 

Standings :

  • id (id auto-increment primary key)

  • user_id (user id)

  • at Credit (integral)

 

Continues to run, assuming redeem page, users choose to redeem their 20,000 bottle of shampoo, how should the background logic design?

 

This site also have to give a thought process, this fact seems simple, but a lot of younger, less experienced friends, may not be able to think quickly out.

 

First you use 20,000 points to be redeemed, then it must be in the points table must be deducted 20,000 points this out, right? So in the design process, we must first have a process of deduction of 20,000 points.

 

Second, you redeem the 20,000 with which what is it?

 

So you still need a separate table, called redeem record sheet, record the user you redeem this much a piece of merchandise with what?

 

This Redeem record table structure is shown below, you are not required in the following table to insert a record, said the number of users of this product which redeem the use?

 

Redeem table :

  • id (id auto-increment primary key)

  • user_id (user id)

  • exchanged_credit (points for redemption)

  • product_id (exchange of goods id)

 

Finally, just inserted into the piece redeem record is not enough, you have to call the warehousing module interface, a new notification module shipments warehousing business applications, and should be shipped redeem the corresponding application, thus ensuring warehouse you can prepare the corresponding commodity shipments.

 

The application delivery configuration substantially corresponding to the following table:

 

Delivery Application Form :

  • id (id auto-increment primary key)

  • of the type (delivery type, 1: buy, 2: redeem)

  • credit_exchange_id (the above mentioned id redeem table)

  • product_id (goods to be shipped id)

 

In fact, there's a lot to simplify application delivery, so the number of fields have arguably had shipped goods, but here you can simplify the process is also all right, after all, is the interview site.

 

A simple drawn flow shown as follows.

 

 

4, logistics and distribution status inquiry, taking into account yet?

 

If the above that the entire business process to the interviewer said, get away with it?

 

of course not!

 

You can stand on the user's point of view, do you still need to see is certainly not redeem the record? In redeem this table to see how much you can redeem points for what merchandise.

 

But you exchange goods distribution schedule, and you can view it? Can not. So you should be in the business process re-taken into account in the distribution of the corresponding logic.

 

In general, a basic logic, it is time production shipments in the application form, call the third-party logistics logistics company to apply for a single interface, so that the warehouse manager packaged goods are ready, waiting for the logistics company delivery of goods to close it.

 

Single logistics companies to carry out logistics and distribution according to this delivery address is certainly one of your addresses in the user's own electronic business platform of choice.

 

At this time, requisition shipping table structure is not shown below?

 

Delivery Application Form :

  • id (id auto-increment primary key)

  • of the type (delivery type, 1: buy, 2: redeem)

  • credit_exchange_id (the above mentioned id redeem table)

  • product_id (goods to be shipped id)

  • express_no (single stream number)

 

Therefore, in the production of a single application delivery, come to call third-party logistics logistics company to apply for a single interface, so a single application delivery is a single number of logistics and redeem each record with the shipment application by id single associate.

 

Such exchange for each record, is not to be found in a single application delivery logistics a single number on the page, and then call the third-party logistics company logistics interface based on a single number, to acquire distribution schedule?

 

This is a very logical thinking techniques typical business system implementation, a rich experience of qualified engineers, often they have a certain amount of business thinking, well to consider user logical business systems, thrust reversers own system technology logic.

 

Whole procedure, as shown below:

 

 

 

5, to ensure that matters

After the stroke along the entire business process, the next step involves the consideration of the technology. You have to think about it, how can such a business transaction system does not it?

 

Deduction of points, redeem new record, new shipping application form, three steps must be completed either together or fail together. In other words, these three steps must be within a transaction of.

 

There is a problem, a business platform for their business systems, contains only integral service. But the warehousing services typically deployed independently of a system or a stand-alone service.

 

In other words, the deduction of points and redeem new record can be a service there is a transaction, but the new shipping application form, he is in another service where, and how to ensure this transaction it?

 

A friend may immediately answer: use distributed transactions ah! Do not worry, we can start with the most simple model to achieve it.

 

In one example, point service transaction code block, execute deduction integration, new redeem recording two steps.

 

Then remember, in the transaction code block, the last step call interface warehousing services, if the interface call is successful, then the transaction can be committed. If the interface call fails, then throw an exception so that the transaction is rolled back, so you can not?

 

This process is as follows:

 

        Integral service transaction {

               -> points deduction

               -> Add redeem record

            -> call Warehousing Services

        }

 

 

6, the introduction of messaging middleware

In fact, the above design is theoretically no problem, but here you ignore a problem, in this business scenario, service integration is not necessary synchronous calls warehousing services.

 

Because Redeem a user operation is performed, assuming your storage service call when generating shipment of Requisition interface third-party logistics company, was stuck or fail, how do?

 

At this point they'll probably see after the redeem button clicks, there may be tens of seconds card can not be executed successfully, so the system is designed so that errors on the page.

 

That should be how to do it? You have got to be here to introduce decoupling asynchronous messaging middleware technology, to ensure the user after clicking Redeem button to return as soon as possible. As shown below:

 

 

7, a retry mechanism is introduced

Yet here it is OK? not yet!

 

Once the introduction of messaging middleware, benefit is the user clicks the redeem button is directly deducted points and redeem new record in integrating services, and then sends a message to the messaging middleware in the over, very fast, to ensure that the user experience.

 

But the downside is, if the implementation of new storage services delivery application fails how to do?

 

This time on the need to introduce a reliable messaging service, and he needs to go to ensure the completion of the new warehouse delivery services will apply in this matter.

 

Specific process is as follows:

  • Integral reliable service send messages to the message service, reliable messaging service message in a new record in the table, and then sends the message to the MQ (Message Oriented Middleware)

     

  • Then add warehousing services consumer news delivery application form, if successful callback interface to a reliable messaging service say that they are successful, reliable messaging services can update the local record status message table for success

     

  • If there is no reliable notification message service warehousing services for a long time I was a success, reliable sources of non-stop service to retry sending the message again

 

With this design, we can ensure reliable message service will allow unlimited retries warehousing services to ensure successful implementation. Coupled with the retry mechanism, the overall flow chart as shown below:

 

 

 

8, the introduction of mechanisms idempotent

One last question, if the third-party logistics warehousing services card application system link logistics alone, prolonged obstruction, there is no reliable sources callback notification service.

 

But reliable messaging services over a period of time, the feeling did not receive a callback notification on their own to retry sending the message that this would not make two new warehousing services delivery application form?

 

So we have to ensure that new warehousing service delivery requisition idempotency, in fact, very simple, look at the structure of a single application delivery table:

 

Delivery Application Form :

  • id (id auto-increment primary key)

  • of the type (delivery type, 1: buy, 2: redeem)

  • credit_exchange_id (the above mentioned id redeem table)

  • product_id (goods to be shipped id)

  • express_no (single stream number)

 

Just create a unique index on the "credit_exchange_id" field will be able to ensure that each record can only redeem create a single application delivery, if it will be repeated to create a unique index is blocked, so as to ensure the power of this behavior, etc. of the.

 

So far, this topic duct system design answers all over.

 

 

 

9, a summary of this kind of interview questions

By analyzing this article, you can see this kind of thinking for an answer open-ended interview questions, first of all have to come from the business consider this part of the system which business should have, how to achieve business process?

 

The second is that you have to consider business scenarios facing the corresponding time, this system will be what technical challenges, all aspects of which may have a technical problem?

 

For then should these technical challenges and technical issues, the site gives you some ideas. As long as you can give a rough idea, such as which direction should be to solve, what mechanism should be introduced.

 

To be honest, most people do not actually done this kind of system. For example, let you design a spike system, how to design?

 

I ask, how many people really did domestic spike system? In fact, the interviewer is just examine this issue by your technical, technical knowledge, the accumulation of a variety of conventional technical solutions, as well as on-site business analysis, technical analysis of the problem, and then based on your past accumulation of technology, give a reasonable solution a capability.

 

This ability is the ability of a senior Java engineer must have, because if you are a more than 5 years experience in senior engineer, then you must be able to independently responsible for a system in the team.

 

At this point you must have the ability, the problems facing the project, to be able to analyze the business, analyze technical issues, and then given a reasonable technical solutions and architecture design.

Guess you like

Origin www.cnblogs.com/HF-Made/p/11532703.html