TrackIt — E-Commerce Technical Article #2 — Implementation
In a previous article, titled ‘Building E-Commerce Order Management Systems — Technical Article #1 — Architecture’, the TrackIt team outlined the different strategic and architectural choices developers can make to build robust, cost-effective, and flexible order management systems.
This second article in the E-Commerce Technical series focuses on the implementation process and details the different steps involved in setting up an OMS.
Step 1: Creating a Serverless Project Using Serverless Framework Documentation
The first step in the implementation process is to create a Serverless project. Readers can follow the instructions in the Serverless Framework Quick Start Guide to install the Serverless Framework open-source CLI and deploy a sample service that reports deployment information and other optional metrics to the Serverless Framework Dashboard.
Step 2: Setting Up the Logic for the OMS
The second step in the implementation process is to set up the logic for the order management system. This begins with the addition of the first step Function and Lambda functions.
Adding the First Step Function and Lambda Functions
We need to create the serverless.yml
to define the basic Serverless configuration with Step Functions and Lambda functions. In the example below, the state machine has only one state ProcessOrder:
Next, we create the handler src/processOrder/index.js
Configuring the OMS Database
After adding the first Step Function, the next step is to configure the OMS database and define a model that defines how data is stored within the database.
We use the Sequelize ORM (Object-Relational Mapping) to connect to our database — the configuration is added in src/processOrder/index.js
. We also define a simple Order
model and create an entry every time the Step Function is called. The database table is created manually for the sake of simplicity.
Sending Messages to the SQS Queues
Once the OMS database is configured and the orders are saved in the database for each execution, we set up an SQS queue that receives an order creation notification when a new order is created.
We attempt to send a message to a FIFO (First-In-First-Out) SQS queue — predominantly used to forward messages between services — and we verify that it was sent properly.
Adding Error Handling
Adding error handling to automatically re-execute Lambdas in case of errors, such as temporary database connection issues, is important when setting up a reliable and robust order management system.
We edit the serverless.yml
file to add a retry mechanism. The interval, max attempts and backoff rate need to be adapted to the reader’s project.
Adding GraphQL to Expose OMS Data to Other Services
Adding GraphQL is essential when users wish to implement external services that request OMS data for their functioning.
The serverless.yml
file is edited to add the AppSync configuration that enables users to configure the GraphQL API and make it available to third-party services.
The next step is to create a GraphQl schema (appSync/schemas/schema.graphql
) that matches the order table:
We then need to create default mapping templates to define the request/response format for the handler.
appSync/mappingTemplates/requests/default.vtl
appSync/mappingTemplates/responses/default.vtl
Lastly, we define the GraphQL resolver appSync/resolvers/OrderResolver.js
that processes the requests and prepares the response.
We can now execute GraphQL queries on the endpoint or on the AWS console. Here is an example:
Additional Information
The package.json
file used for this project is as follows:
At this point, readers will have implemented a Serverless project that’s connected to an OMS database and also has the basic logic required to run an order management system.
Step 3: Resolving Common Issues
Common Issue #1: Organizing the Project when there are many Lambdas and Step Functions
Solution: Developers can split the project into different folders to ensure readability.
Common Issue #2: Excessive Database Load
Solution: Developers can create SQL indexes to optimize SELECT data requests.
Common Issue #3: Lambda Quota/Rate Limit
Solution: Companies can Contact AWS to request higher quotas on Lambda functions.
Common Issue #4: Setting up an Environment for Dev Testing
To develop features, developers should have their own environment to run tests. Developers often realize that it’s not easy to run E2E tests since they require a lot of setup.
Solution: Developers can write a script that creates the database, deploys the stack, generates the env file, and sets up all the default values and migrations.
Conclusion
This article has detailed the steps readers can take to implement robust order management systems and has also addressed some of the most common issues developers face when setting up an OMS. The next article in the E-Commerce Technical series will focus on OMS testing and different considerations companies need to make in order to test and ensure the proper functioning of their order management systems.
About TrackIt
TrackIt is an Amazon Web Services Advanced Consulting Partner specializing in cloud management, consulting, and software development solutions based in Venice, CA.
TrackIt specializes in Modern Software Development, DevOps, Infrastructure-As-Code, Serverless, CI/CD, and Containerization with specialized expertise in Media & Entertainment workflows, High-Performance Computing environments, and data storage.
TrackIt’s forté is cutting-edge software design with deep expertise in containerization, serverless architectures, and innovative pipeline development. The TrackIt team can help you architect, design, build, and deploy customized solutions tailored to your exact requirements.
In addition to providing cloud management, consulting, and modern software development services, TrackIt also provides an open-source AWS cost management tool that allows users to optimize their costs and resources on AWS.