Hawker Payment System

Exploring microservce architecture

Jan 2022 - May 2022

Source Code

Skills: Python • Flask • Microservices • Docker • Kong API Gateway • VueJS • Tailwind CSS • MySQL • REST API

Coursework Project

7 min read


Introduction

This project was done as part of a requirement for the module IS213 - Enterprise Solution Development (ESD). It’s main focus was to facilitate the learning of concepts such as the microservices and service oriented architecture (SOA), containerization, writing, and documenting Representational State Transfer (RESTful) APIs.

Requirements

The key learning outcome of the project was for the team to build an enterprise solution that is based on the microservice architecture for a business scenario.

Other requirements include:

  • Using a minimum of one external service or API
  • Use HTTP communication between some microservices
  • Use AMQP based communication between some microservices
  • Create, read, update, delete (CRUD) functionalities for microservices
  • Have at least one web-based Graphical User Interface (GUI)
  • Usage of Docker and Docker Compose
  • Using JavaScript Object Notation (JSON) data in some of the microservices
Business scenario

The central problem that my team tackled was that hawker centers are always packed with long queues during peak hours, with customers having to stand and wait after ordering.

The team’s solution was to develop a web aplpication that can replace both the manual ordering and payment processes, aiming to reduce the congestion and hassle experienced in hawkers during peak hours.

Tech stack

Our main technical stack and their use cases

  • VueJS : Main frontend framework for coding out the GUI
  • Python and Flask : Writing backend RESTful API routes and services
  • Docker : Used for containerizing each service
  • Kong API Gateway : Used for managing, configuring, and routing requests to our APIs
  • MySQL : Backend database for storing data
  • Tailwind CSS : CSS Framework for styling the user interface
  • RabbitMQ : Open source message broker that supports AMQP
  • Twilio : External API used for it’s messaging capabilities
Overview
Customer (client) interface

A user is synonymous with a customer, and the main action a user performs is to browse the hawkers and menu, followed by placing an order.

customer MS design
Microservices design (customer)

Functionalities include:

  • Update user details such as email and password
  • Browse hawkers by categories i.e., halal or vegetarian
  • View a food item details
  • Update wallet to withdraw or top up money
  • Placing an order and subsequently viewing the status of the order
Hawker (client) interface

A hawker is a tenant in a hawker center, and the main actions the hawker performs include accepting, rejecting, and completing food orders, updating their food menu, and viewing all orders and order history.

hawker MS design
Microservices design (hawker)
Process flow

Let’s go through a possible scenario of placing an order.

place order flow
Process when customer places an order

When a customer places an order, the following steps happen:

  • Customer uses the UI to invoke the hawker service, making a HTTP GET request. In this case, a GET request to /hawker/halal/1 was made to get all hawkers that are halal-certified, illustrated by steps 1 and 2 on the left diagram.
  • Customer then chooses a hawker to order from, and then add items to a cart.
  • Customer invokes the Place Order microservice by making a POST request, which orchestrates the ‘place order’ process.
  • A validation check is made to ensure that the customer has enough money in the wallet. The process ends if there is insufficient balance.
  • If there is sufficient balance, an order, as well as a escrow record is created. Money is deducted from the customer’s wallet, and this amount is held in escrow.
  • If there are zero errors, the order is successfully created, and the customer get’s an SMS notification confirming their order.

Subsequently, a hawker will receive the order and can choose to either accept or reject the order.

manage orders
Hawker's order management interface
Learnings

Main takeaway for this project was definitely learning how to write and document APIs, while designing a solution based on the microservices architecture, which allows services to be loosely coupled and independently deployable.

Working in a collaborative environment has highlighted to me the importance of proper documentation and standardization across the board, reducing the time and resources spent on tasks such as figuring out how the code works, or debugging a certain error that can be easily solved with proper documentation.

Another big takeaway was making use of containerization platform such as Docker, isolating applications so that developers do not have to deal with dependency and configuration issues which are pre-defined within Dockerfiles and yaml files.

complex/place_order.Dockerfile
FROM python:3-slim
WORKDIR /usr/src/app
COPY ./requirements.txt ./amqp/amqp.reqs.txt ./
RUN python -m pip install --no-cache-dir -r requirements.txt -r amqp.reqs.txt
COPY ./place_order.py ./invokes.py ./amqp/amqp_setup.py ./
CMD [ "python", "./place_order.py" ]
Dockerfile code snippet

With the implementation of microservices, comes the usage of an API gateway, which in this case we used Kong as it has an accompanying Graphical User Interface (GUI) which made it simple and easy to configure and manage our services. However, due to the steep learning curve and a lack of time, we were unable to dive too deep and fully utilise the benefits of having an API gateway in our application, but nevertheless, the exposure to such a software is a learning point in itself.

manage orders
Konga GUI for managing services on localhost:1337

Finally, this project also allowed me to learn a little more about the Advanced Message Queuing Protocol (AMQP) and RabbitMQ (message broker), but again, due to the lack of time and low priority, we were unable to explore and fully maximise the benefits of these technologies.

manage orders
RabbitMQ GUI on localhost:15672
Conclusion

I thoroughly enjoyed and took away many lessons from this module, and it is without a doubt one of my favorite module in SMU. However, for a simple project such as this, making use of microservices may be a little bit of an overkill and I doubt I will be applying many concepts learnt here on other projects. But hey, it doesn’t hurt to learn new things, does it? 😄

This is just a introductory module to the world of backend development and hosting applications, just to get our feet wet. I know that the project is (in many ways) neither perfect nor well-written, so do take this post as just a personal reflection and documentation of my journey!

Chew Yi Xin 2023  •  Last updated Feb 2024