Order synchronization
Background
Orders are the core data of sellers. Many of sellers’ daily work revolves around orders. The basic function of the application is to Ensure that orders are displayed in front of sellers in real time and completely. Since API requests rely on the network, there are problems such as network instability and long synchronization time, so the application must synchronize Taobao order data locally. How to quickly and completely synchronize orders to the local area is an issue that will be discussed in this plan.
There are two ways to synchronize orders: 1. Synchronization through API 2. Based on rds order synchronization service. This article mainly analyzes the scenario of using API to synchronize orders. For information on how to use RDS order synchronization, please refer to //open.taobao.com/docs/doc.htm.htm?articleId=101587&docType=1&treeId=2
Explanation of terms
Online orders: Orders sold by the seller within three months.
Incremental order: Compared with the orders that have been synchronized to the local, any order that has been changed on Taobao is an incremental order.
Message service: A channel that pushes data (transaction) changes to the client (application) in real time through HTTP long connections.
APIIntroduction
##taobao.trades.sold.get - Get three months Online orders that have been sold within the period are suitable for use during user initialization. ISVs should not use this interface to obtain incremental orders. It is not recommended to use this interface or use it as little as possible.
taobao.trades.sold.increment.get – Get incremental orders, applicable to orders that are changed during incremental synchronization after user initialization, ISV should not Use this interface to obtain orders within three months.
taobao.trade.fullinfo.get - Get the details of a single order.
Implementation plan
Order synchronization is mainly divided into two steps: initialization and incremental acquisition:
1. Initialization is to synchronize all online orders within 3 months, which takes a long time;
2. Incremental acquisition is to synchronize the changed orders on Taobao, which generally takes a shorter time.
#The following solutions will focus on how to initialize and incrementally obtain.
##Option 1
Synchronization process:
##Core steps:
##u
Three-month data: Get the order IDs created within 3 months through taobao.trades.sold.get, and then taobao.trade.fullinfo.getGet order details
u Incremental data: Get the incremental order ID from now on through taobao.trades.sold.increment.get, then Get order details via taobao.trade.fullinfo.get
Scope of application:
Suitable for ISV testing order synchronization function or small and medium-sized sellers in production environment for order synchronization. This solution is relatively inefficient. Unless the update cost of old applications is very high, it is not recommended for everyone. It is recommended to adopt the following solution.
Option 2
Synchronization process:
##Core steps:
a) First, use taobao.trades.sold.get to obtain the data within 3 months to yesterday 23:59:59 Created order details
u Three months of data:
b) Then, use taobao.trades.sold.increment.get to get the incremental order ID from 00:00:00 today to now, and then use taobao.trade .fullinfo.get Get order details
u Incremental data: monitor orders in real time through the message service client Change the message, and then obtain the order details through taobao.trade.fullinfo.get
Applicable scope:
is suitable for all types of sellers. It is a relatively complex but most efficient solution among all solutions. It is recommended for all ISVs to adopt.
Experience sharing
Missing order problem:
M When obtaining orders through taobao.trades.sold.get and taobao.trades.sold.increment.get, enter the transaction type as a parameter By default, only some types of orders are queried. To query all types of orders, all transaction types must be explicitly provided as the type input parameter.
M When obtaining incremental orders through taobao.trades.sold.increment.get, the return result is If the orders are sorted in reverse order of modification time, the paging must be turned from back to front to prevent orders from being missed due to changes in orders during the forward page turning process.
M When obtaining incremental orders through taobao.trades.sold.increment.get, the starting time of each acquisition is appropriately moved forward by 10 minutes Left and right (double11It is recommended to move forward 30about minutes during a big sale) to prevent extreme circumstances due to Missing orders due to Taobao system pressure causing delays in updating orders to the database.
M When receiving order change messages through active notifications, you need to handle server restarts or network disconnections. The resulting message loss problem, please check the message service for details.
Performance issues:
##M taobao.trades.sold.get Get the seller’s orders for three months
##nUsing the paging method with parameter use_has_next=true can avoid the count(*) generated by each API request to the Taobao database, thereby significantly improving speed and stability.
n Because the interface for obtaining orders within three months is filtered by the creation time, and the creation time It is immutable, so turning pages from front to back will not lead to missing orders, so you can save the count(*) in the first step, and directly use the parameter use_has_next=true to obtain it in pages, until has_next= is returned in the result. Terminate page turning when false. n If the fields returned by the interface cannot meet the needs of the application, it is strongly recommended to only obtain the fields=tid field, and then pass taobao. trade.fullinfo.get gets order details. n Since the seller’s three-month order volume is relatively large, it is recommended to divide the three-month order into Obtained on a daily basis to reduce the amount of record scanning of the Taobao database in a single request to improve efficiency. M ##taobao.trades.sold.increment.getGet incremental order n Using the paging method with input parameter use_has_next=true can avoid the count(*) generated by the Taobao database during each API request. , thereby significantly improving speed and stability. n Because the interface for obtaining incremental orders is filtered by modification time, and the modification time is variable , so you need to turn the pages from back to front to avoid missing orders. To turn pages from back to front, you must know the last page, so you must use use_has_next=false in the first API request to count the total number of orders, calculate the total number of pages, and then set use_has_next=true to terminate the order statistics and turn from back to front. Page. n If the fields returned by the interface cannot meet the needs of the application, it is strongly recommended to only obtain fields=tid This field is then used to obtain the order details through taobao.trade.fullinfo.get. M When using taobao.trades.sold.get/taobao.trades.sold.increment.get to only obtain the tid field, it is recommended to set page_size to The maximum value reduces the number of API requests and improves efficiency. When obtaining multiple fields, you can set page_size according to your own network conditions. It is recommended to set it to about 50. Exception handling: M Synchronous orders are generally processed using multi-threads. Since API requests have frequency limits for APPs, when setting the thread pool size, you need to set it according to the API call frequency allowed by TOP to avoid the current limit. As a result, the application cannot call the API for a long time. M For ISP type errors or network connection errors returned by the API, the application thread should sleep for a while Automatically retry. For ISV type errors returned by the API, the application needs to record logs for future troubleshooting and do not retry. FAQ