Ahmed Codes

Building an application with Microservices and Machine Learning

By Ahmed Sulaimon2025-05-07

Developing a production-grade application that combines microservices architecture with machine learning was both a technical challenge and a rewarding learning experience. This post outlines my process of designing and implementing a real-time grocery price comparison tool covering the vision, system architecture, ML integration, CI/CD & DevOps, challenges, Technical Decisions & Trade-offs, What I’d Improve and key takeaways.


1. The Vision

The goal was to build a platform that empowers users to make smarter grocery decisions by:

This tool aims to bring dynamic pricing awareness to everyday grocery shoppers, something typically reserved for large-scale retailers or marketplaces.


2. System Architecture

To ensure scalability and maintainability, I adopted a microservices-based architecture with clear service separation:

Architecture Overview:

   Frontend (Flutter) → API Gateway (Flask) → [Scraping Service] ↔ [Price Analysis Service(ML)]

All services were dockerized for modular deployment and fault isolation.


3. Machine Learning Component

At the heart of the system lies a Weighted Moving Average (WMA) model used to predict near-future price movements. The ML pipeline included:


4. CI/CD & DevOps

To maintain smooth development and safe deployments, I implemented:

This allowed us to test and deploy services independently without disrupting the entire system; a major advantage of the microservices model.


5. Challenges Faced

As with any real-world system, the project presented several hurdles:


6. Technical Decisions & Trade-offs

Why Weighted Moving Average (WMA) Over ARIMA or LSTM?

Although I considered ARIMA and LSTM, I chose WMA because:

This trade-off struck the right balance between simplicity and practical performance.

Why Flask for the API Gateway Instead of FastAPI or Express?

Despite FastAPI's modern async features, I chose Flask due to:

Why Selenium for Scraping?

I used headless Selenium because:

Bot detection mitigation included:

Why Microservices Instead of a Monolith?

Although microservices introduced some complexity, they were the better choice for:


7. What I’d Improve

Replace WMA with Adaptive Forecasting

While WMA was effective, it lacks the ability to model non-linear patterns and seasonality. In the future, I’d explore:

Move Scraping to Serverless or Queue-Based Infrastructure

Currently, scraping runs on a fixed schedule within a container. A better approach would be:

Improve API Gateway Security

The current setup lacks critical security layers. Future upgrades would include:

Add Internationalization and More Retailers

To scale globally, the system should support:


8. Lessons Learned

This project helped reinforce key software engineering principles:


9. Final Reflections

What began as an ambitious stack experiment turned into a robust, deployable platform. It challenged me to think like both a systems architect and a data engineer; skills that are increasingly in demand.

I now feel significantly more confident tackling roles that involve distributed architecture, data pipelines, and machine learning integration.