designing a hybrid microservices system

 You’re essentially designing a hybrid microservices system using:

  • .NET Core + SQL Server → For reporting, dashboards, client data

  • Python + MySQL → For robot data collection, control, and telemetry

  • Ocelot API Gateway → As the single entry point for both ecosystems


Let’s break it down step by step πŸ‘‡




Component Tech Purpose
Gateway Ocelot (.NET 8 Web API) Routing, load balancing, auth
Service 1 ASP.NET Core Web API + SQL Server Reporting & Client Dashboard
Service 2 Python FastAPI + MySQL Robot data ingestion & management
Communication REST API over HTTP Synchronous calls between services
Deployment Docker (optional) Isolate and scale services independently


πŸ—️ 3. Implementation Plan

Step 1️⃣ – Create the Python Microservice (RobotService)

Use FastAPI for lightweight REST APIs.

Directory: /RobotService

Install FastAPI

pip install fastapi uvicorn mysql-connector-python

main.py

from fastapi import FastAPI
import mysql.connector
app = FastAPI()
def get_db_connection():
return mysql.connector.connect(
host="localhost",
user="root",
password="password",
database="robotdb"
)
@app.get("/api/robot/{id}")
def get_robot_data(id: int):
conn = get_db_connection()
cursor = conn.cursor(dictionary=True)
cursor.execute("SELECT * FROM robot_data WHERE id=%s", (id,))
result = cursor.fetchone()
conn.close()
return result

Run:

uvicorn main:app --reload --port 7000

Step 2️⃣ – Create the .NET Core Microservice (ReportService)

Command:

dotnet new webapi -n ReportService

Controllers/ReportController.cs

[ApiController]
[Route("api/[controller]")]
public class ReportController : ControllerBase
{
[HttpGet("{robotId}")]
public IActionResult GetReport(int robotId)
{
// This could later query SQL Server
return Ok(new { RobotId = robotId, Status = "Completed", Date = DateTime.Now });
}
}

Run on port 6000:

dotnet run --urls=http://localhost:6000

Step 3️⃣ – Create Ocelot API Gateway

Command:

dotnet new webapi -n ApiGateway

Install Ocelot:

dotnet add package Ocelot

ocelot.json

{
"Routes": [
{
"DownstreamPathTemplate": "/api/robot/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{ "Host": "localhost", "Port": 7000 }
],
"UpstreamPathTemplate": "/robot/{everything}",
"UpstreamHttpMethod": [ "Get", "Post" ]
},
{
"DownstreamPathTemplate": "/api/report/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{ "Host": "localhost", "Port": 6000 }
],
"UpstreamPathTemplate": "/report/{everything}",
"UpstreamHttpMethod": [ "Get", "Post" ]
}
],
"GlobalConfiguration": {
"BaseUrl": "http://localhost:5000"
}
}

Program.cs

using Ocelot.DependencyInjection;
using Ocelot.Middleware;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddJsonFile("ocelot.json", optional: false, reloadOnChange: true);
builder.Services.AddOcelot();
var app = builder.Build();
await app.UseOcelot();
app.Run();

Run:

dotnet run --urls=http://localhost:5000

✅ Step 4️⃣ – Test via Ocelot Gateway

ServiceGateway URLResult
Robot Data (Python)GET http://localhost:5000/robot/api/robot/1Returns robot info from MySQL
Report Data (.NET)GET http://localhost:5000/report/api/report/1Returns report from SQL Server

Now both Python and .NET microservices are accessible via a single unified API Gateway 🎯


πŸš€ Step 5️⃣ – Next-Level Enhancements

FeatureDescription
πŸ” AuthenticationUse JWT auth in Ocelot (can validate before routing)
πŸ—„️ Centralized ConfigUse Consul or etcd for dynamic routes
🧩 Async CommunicationIntroduce RabbitMQ or Azure Service Bus for robot data notifications
🐳 ContainerizationRun all three services via Docker Compose
πŸ“Š MonitoringAdd Serilog + Prometheus + Grafana for metrics


Comments

Popular posts from this blog

.NET Core Interview Questions and Answers for 10+ Years Experienced Professionals

What are SOLID Principles?

.NET Core Senior Interview Q&A