Skip to content

Instantly share code, notes, and snippets.

Building Production ML Microservices: From Classical ML to RAG — A Template That Scales

How I built two production-grade ML systems using the same architectural pattern — and what I learned along the way.


The Problem with Most ML Projects

Most ML tutorials end the same way — a Jupyter notebook, a trained model, maybe a Flask app if you're lucky. But none of them answer the real question:

@Hg03
Hg03 / raw.csv
Created December 12, 2025 18:00
person_name age date gender platform daily_screen_time_min social_media_time_min negative_interactions_count positive_interactions_count sleep_hours physical_activity_min anxiety_level stress_level mood_level mental_state
Reyansh Ghosh 35 1/1/2024 Male Instagram 320 160 1 2 7.4 28 2 7 6 Stressed
Neha Patel 24 1/12/2024 Female Instagram 453 226 1 3 6.7 15 3 8 5 Stressed
Ananya Naidu 26 1/6/2024 Male Snapchat 357 196 1 2 7.2 24 3 7 6 Stressed
Neha Das 66 1/17/2024 Female Snapchat 190 105 0 1 8 41 2 6 6 Stressed
Reyansh Banerjee 31 1/28/2024 Male Snapchat 383 211 1 2 7.1 22 3 7 6 Stressed
Myra Kale 25 2/8/2024 Female Snapchat 516 284 1 3 6.4 8 3 8 5 Stressed
Ananya Kulkarni 29 2/19/2024 Other Snapchat 328 180 1 2 7.4 27 3 7 6 Stressed
Meera Das 28 1/11/2024 Female Facebook 394 138 1 1 7 21 2 7 6 Stressed
Vihaan Naidu 31 1/22/2024 Male Facebook 326 114 0 1 7.4 27 2 6 6 Stressed
user_id subscription_type country avg_daily_minutes number_of_playlists top_genre skips_per_day support_tickets days_since_last_login churned
user_1 Premium US 134.9 4 Electronic 6 0 1 0
user_2 Premium PK 165.7 5 Pop 8 0 12 0
user_3 Free DE 45.9 3 Classical 3 0 3 0
user_4 Premium PK 106.0 0 Jazz 7 0 3 0
user_5 Premium US 89.6 5 Country 2 1 6 0
user_6 Free IN 17.6 0 Rock 6 2 7 1
user_7 Free UK 43.7 2 Hip-Hop 1 1 0 0
user_8 Premium BR 131.3 3 Classical 7 0 1 0
user_9 Free FR 41.9 5 Country 4 0 0 0
import numpy as np
class LinearRegression:
def __init__(self, lr = 0.001, n_iters=1000):
self.lr = lr
self.n_iters = n_iters
self.weights = None
self.bias = None
Trip_Distance_km Time_of_Day Day_of_Week Passenger_Count Traffic_Conditions Weather Base_Fare Per_Km_Rate Per_Minute_Rate Trip_Duration_Minutes Trip_Price
19.35 Morning Weekday 3.0 Low Clear 3.56 0.8 0.32 53.82 36.2624
47.59 Afternoon Weekday 1.0 High Clear 0.62 0.43 40.57
36.87 Evening Weekend 1.0 High Clear 2.7 1.21 0.15 37.27 52.9032
30.33 Evening Weekday 4.0 Low 3.48 0.51 0.15 116.81 36.4698
Evening Weekday 3.0 High Clear 2.93 0.63 0.32 22.64 15.618000000000002
8.64 Afternoon Weekend 2.0 Medium Clear 2.55 1.71 0.48 89.33 60.202799999999996
3.85 Afternoon Weekday 4.0 High Rain 3.51 1.66 5.05 11.2645
43.44 Evening Weekend 3.0 Clear 2.97 1.87 0.23 101.1216
30.45 Morning Weekday 3.0 High Clear 2.77 1.78 0.34 110.33
class Solution:
def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
"""
Do not return anything, modify nums1 in-place instead.
"""
while(n>0):
nums1[m+n-1]=nums2[n-1]
n=n-1
nums1.sort()

Problem Statement

Brute Force Approach - In this approach, we'll consider each element and check for every next greater element

// Time Complexity - O(N^2)           Space Complexity - O(1)
class Solution {
public:
    vector<int> nextGreaterElements(vector<int>& nums) {
 vector result(nums.size(), -1); // Array to store next greater element of each element

Problem Statement

Brute Force - We can use two extra vector in which one stores only zeroes and another stores non zeroes and then append zeroes from first array to another which contain non zeroes at beginning. But on leetcode, we have to solve it in-place.

Optimized Approach -

// Time Complexity - O(N)            Space Complexity - O(1)
class Solution {
public:
@Hg03
Hg03 / cloudMain.md
Last active December 23, 2022 00:28

Explain OAuth 2.0 .

OAuth 2.0, which stands for “Open Authorization”, is a standard designed to allow a website or application to access resources hosted by other web apps on behalf of a user. It replaced OAuth 1.0 in 2012 and is now the de facto industry standard for online authorization. OAuth 2.0 provides consented access and restricts actions of what the client app can perform on resources on behalf of the user, without ever sharing the user's credentials.

Principle - OAuth 2.0 is an authorization protocol and NOT an authentication protocol. As such, it is designed primarily as a means of granting access to a set of resources, for example, remote APIs or user data. OAuth 2.0 uses Access Tokens. An Access Token is a piece of data that represents the authorization to access resources on behalf of the end-user. OAuth 2.0 doesn’t define a specific format for Access Tokens. However, in some contexts, the JSON Web Token (JWT) format is often used. This enables token issuers to include data in the token

@Hg03
Hg03 / mongo.md
Last active December 20, 2022 17:35

Theory

Difference

Basis of Comparison NoSQL RDBMS
Definition Non-relational databases, often known as distributed databases, are another name for NoSQL databases. RDBMS, which stands for Relational Database Management Systems, is the most common name for SQL databases.
Query No declarative query language SQL stands for Structured Query Language.
Scalability NoSQL databases are horizontally scalable RDBMS databases are vertically scalable
Design NoSQL combines multiple database technologies. These databases were created in response to the application's requirements. Traditional RDBMS systems use SQL syntax and queries to get insights from data. Different OLAP systems use them.