Design E-Commerce Applications with Microservices Architecture

In this article, we are going to learn how to design E-Commerce Applications with Microservices Architecture.

Microservice Architecture — E-Commerce App

Designing an e-commerce application using microservices architecture can be a complex task, but before designing E-Commerce application, we should understand E-Commerce Domain with Use Cases, Functional and Non-Functional Requirement that provide to design architecture properly.

I have just published a new course — Design Microservices Architecture with Patterns & Principles.

Architecture Design Flow

Before we design any architecture we will always start from Problem which is Business Problem that drive our design considerations.

Software Architecture: Way of Learning

Because If there is no Business Problem or any Problem can’t related to Business, then most probably you don’t need to change your Architecture if you do, that means you are doing over-engineering.

  • So what is the main problem of E-Commerce Application ?

First Problem: Sell Products Online

We will iterate our designs with following to our course flow which starts with the Problem. And our first and main problem: Sell Products Online

To cover this problem, We would like to

  • Create E-Commerce Web Application
  • Identify use cases and non-functional requirements
  • List products, add basket and ordering products.
  • Available 7/24
  • Handle good amount of request per second
  • Provide acceptable latency for users
E-Commerce Application

These are our initial requirements for creating e-commerce application. In order to solve this problem, we will start with

  • Understand Problem
  • Understand E-Commerce Domain
  • Functional & non-functional requirements
  • Use cases

Understand E-Commerce Domain — Use Cases — Functional Requirement

We are going to learn our project domain. Our project domain will be the e-commerce application. It includes buying and selling products or services online through a variety of electronic channels such as websites, mobile apps, or other electronic platforms. So we will understand E-Commerce Domain with all Use Cases. And focus on the “Functional Requirement”.

It doesn’t matter which architecture we are going to apply when analyzing our domain. So the first step always should be the understanding your domain and decomposing it into small pieces.

Lets Starting Our Project. This project will be the e-commerce web application. So we should define our basic use case analysis. Its really important to understand what you will develop and its crucial that defining your use cases. There are several way to analysis the e-commerce domain. We can follow several steps like;

  • Requirements and Modelling
  • Identify User Stories
  • Identify the Nouns in the user stories
  • Identify the Verbs in the user stories

So after that we can put all together into object interaction diagram. And these diagram would be our potential microservices if we choose the microservices architecture. But now we will start a small e-commerce application. That's why its good to start a minimum requirements.

E-Commerce Functional Requirements

Now lets elaborate the Functional Requirements of our E-Commerce application: Functional Requirements:

  • List products
  • Filter products as per brand and categories
  • Put products into the shopping cart
  • Apply coupon for discounts and see the total cost for all of the items in shopping cart
  • Checkout the shopping cart and create an order
  • List my old orders and order items history

E-Commerce User Stories — Use Cases

Now lets identify the use cases of our E-Commerce application, Another way to define these FRs is converting them to Use Case items. User Stories:

  • As a user I want to list products
  • As a user I want to filter products as per brand and categories
  • As a user I want to put products into the shopping cart so that I can check out quickly later on
  • As a user I want to apply coupon for discounts and see the total cost for all of the items that are in my cart
  • As a user I want to checkout the shopping cart and create an order
  • As a user I want to list my old orders and order items history
  • As a user I want to login the system as a user and the system should remember my shopping cart items

As you can see that we have understood our E-Commerce Domain,
write down our Functional Requirement and Use Cases.

Understand E-Commerce Domain — Non-Functional Requirement

We understood E-Commerce Domain with all Use Cases. And now we will focus on the “Non-Functional Requirement”. We can also call these requirements as a “-ilities” that system have.

Non-Functional Requirements

Non-functional requirements for an e-commerce microservices application describe the quality attributes that the system should possess to meet the needs of its users and stakeholders. The main non-functional requirements will be Scalability, Reliability — Availability, Maintainability — Usability and Efficiency.

Scalability and reliability are measures of how well your application can be served to end-users. If our e-commerce application can serve millions of users without noticeable downtime, then we can say the system is highly scalable and reliable.

When you’re working with a product that has a large user base, you should consider these non-functional requirements. Google has to process at least 100K requests per second. Without a robust scalable architecture, it would have been absolutely impossible. Scalability and reliability are probably the major factors for designing good architecture.

So according to our e-commerce application, we can elaborate these non-functional requirements;

  • Scalability: The ability to handle increased load as the number of users or transactions increases. Application should able to serve millions of users.
  • Availability: The system should be available and responsive to users at all times. Application should available 24/7.
  • Maintainability: The system should be easy to maintain, with well-documented code and architecture, and a low cost of change. Application should develop several years.
  • Reliability: The system should perform consistently and reliably, with a low rate of failures or errors.
  • Efficiency: Application should response acceptable latency like less than < 3 second— short response latency.
  • Performance: The system should respond quickly to user requests, with a minimum response time.
  • Security: The system should be secure and protect sensitive information, such as payment information, from unauthorized access or theft.
  • Resilience: The system should be able to handle failures and errors gracefully, with minimal impact on the user experience.
  • Testability: The system should be easy to test, with automated testing tools and processes in place.

These non-functional requirements should be considered when designing and implementing an e-commerce microservices application to ensure that the system meets the needs of its users and stakeholders. By focusing on these requirements, we can build an e-commerce system that is scalable, reliable, and secure.

Request per Second and Acceptable Latency

Lets talk about acceptable latency, how we can make our application for acceptable latency, if our application get use more and more users ? Please see the table:

As you can see in the table, we will start a small e-commerce application that get only 2K concurrent user and gets 500 request per second. And we will design our e-commerce architecture as per these expected volumes. After that, when our business grow and grow, it will required more resources to accommodate bigger request counts, and we will see how we can evolve our architecture as per these numbers.

As you can see that we also understand our Non-Functional Requirements. So according to our functional and non-functional requirements, we are going to design our e-commerce application.

Design Microservice Architecture — E-Commerce App

We are going to design the Microservice architecture step by step. Iterate the architecture design one by one as per requirements. We had a requirement that save the orders see the baskets so on. So according to these requirement we can design e-commerce microservices as image below:

Microservice Architecture — E-Commerce App

Product microservice can use NoSQL document database Shopping Cart microservice can use NoSQL key-value pair database and Order microservice can use Relational database as per microservice data storage requirements.

As you can see that we have design our E-commerce application as a Microservices architecture and handle to FR and NFR requirements like scalability, reliability and so on.

What’s Next ?

Step by Step Design Architectures w/ Course

I have just published a new course — Design Microservices Architecture with Patterns & Principles.

In this course, we’re going to learn how to Design Microservices Architecture with using Design Patterns, Principles and the Best Practices. We will start with designing Monolithic to Event-Driven Microservices step by step and together using the right architecture design patterns and techniques.

--

--

Mehmet Ozkaya
Design Microservices Architecture with Patterns & Principles

Software Architect | Udemy Instructor | AWS Community Builder | Cloud-Native and Serverless Event-driven Microservices https://github.com/mehmetozkaya