DEV Community

taoify
taoify

Posted on

Taoify's API Gateway Design

Taoify has opened up a fully functional RESTful interface, covering five major modules: site, product, order, payment, and logistics. The design goal of this API system is that developers do not need to separately interface with multiple platform APIs, but only need to call the Taoify unified interface to achieve full process synchronization of source, order, and logistics data.

Architecture layering of API gateway

Taoify's API gateway is divided into four layers from top to bottom:

Routing layer: Based on the request URL and HTTP method, distribute the request to the corresponding backend service. Support basic routing functions such as path parameter parsing and request header forwarding.

Authentication layer: Verify the legality of API requests. Adopting the authentication method of API Key+Secret, each developer account is assigned an independent API Key and Secret. The request signature uses the HMAC-SHA256 algorithm to prevent the request from being tampered with.

Flow limiting layer: Limit the frequency of requests for each API Key to prevent excessive calls by individual developers from affecting system stability. The flow restriction strategy is based on the token bucket algorithm and supports configuring different flow restriction thresholds according to the interface dimension.

Adaptation layer: Convert external request parameters into the data format of internal service calls, and convert the return results of internal services into the response format defined by API specifications. This layer isolates the impact of internal service changes on API consumers.

API capabilities of the five major modules

Product Management API: Supports adding, modifying, deleting, and querying product information. Developers can synchronize product data with supply chain management tools through APIs, which is suitable for batch management of products in non stocking mode.

Order Management API: Supports order queries, status updates, and logistics information synchronization. The ERP system can pull new orders through the order API and send back shipping information after processing.

Payment Management API: Supports payment channel configuration, payment status inquiry, and refund initiation.

Logistics Management API: Supports logistics route inquiry, freight calculation, and logistics tracking number backfilling.

Site Management API: Supports site information configuration and multilingual content management.

Idempotent design of API

In key interfaces such as order creation and payment, Taoify requires the caller to pass idempotent_key (idempotent key). The server determines whether a request has been processed based on idempotent keys - processed requests directly return the previous result without repeating business logic. This design ensures that there will be no duplicate orders or deductions in scenarios such as network timeouts and client retries.

The openness and standardization of this API system provide a technical foundation for the integration of Taoify with third-party systems such as ERP, WMS, CRM, etc.

Top comments (0)