close
Skip to content

SaptarshiSarkar12/edge-ai-mesh

Repository files navigation

Edge AI Inference Mesh

A high-performance, edge-native microservices architecture demonstrating Java's capability as an API orchestrator for machine learning workloads. It routes REST telemetry data via gRPC to a headless PyTorch inference node, achieving sub-millisecond network overhead.

Architecture Overview

  • Gateway API (Java/Quarkus): A non-blocking reactive API gateway running on port 8080. It handles user ingress, payload validation, and Protobuf serialization.
  • Inference Service (Python/PyTorch): A dedicated gRPC compute node running on port 50051. It performs Multi-Layer Perceptron (MLP) tensor operations and returns the result.
  • Orchestration: Fully containerized using Docker Compose with an internal isolated bridge network (edge-mesh).

Quick Start

  1. Clone the repository.
  2. Deploy the mesh using Docker Compose:
    docker compose up --build -d
  3. Monitor the startup logs:
    docker compose logs -f

Local Development (Manual Run)

If you prefer to run the services bare-metal for debugging without Docker, you can start the nodes individually.

  1. Start the Inference Node (Python)
    Ensure you have the required artifacts (auto_mpg_weights.pth and auto_mpg_scaler.pkl) in the artifacts/auto_mpg directory.
    cd inference_service
    uv run src/main.py
    The gRPC server will start on port 50051.
  2. Start the Gateway API (Java)
    In a separate terminal, launch the Quarkus dev server.
    cd gateway_api
    ./mvnw clean quarkus:dev
    The REST API will be available on port 8080.

Interactive Inference

Once both containers are running, you can send a vehicle telemetry payload to the Gateway to predict its Miles Per Gallon (MPG) fuel efficiency.

Execute this request in your terminal:

curl -X POST http://localhost:8080/predict \
     -H "Content-Type: application/json" \
     -d '{
       "cylinders": 8.0,
       "displacement": 350.0,
       "horsepower": 165.0,
       "weight": 3693.0,
       "acceleration": 11.5,
       "modelYear": 70.0,
       "origin": 1.0
     }'

Payload Fields & Predictive Factors

The neural network requires 7 specific features to accurately predict efficiency.

  • Physical Metrics: cylinders, displacement, horsepower, weight, and acceleration. These define the raw mechanical output and mass of the vehicle. Heavier, high-displacement engines physically require more fuel to move.
  • modelYear (70 to 82): Captures the technological context of the era. The 1970s oil crises forced rapid innovation in automotive engineering. An engine built in 1982 with 150 horsepower utilizes superior fuel injection and aerodynamics compared to a 1970 engine with the exact same horsepower.
  • origin (1=US, 2=Europe, 3=Japanese/Asia): Acts as a multiplier for regional engineering philosophies. Because gas was historically more expensive in Europe and Japan, cars originating from regions 2 and 3 were engineered specifically for fuel economy. American cars from this era were primarily built for power and cheap gasoline.

Think of it like predicting a runner's marathon time. The physical metrics are their height and weight. The model year represents modern advancements in sports science and shoes. The origin represents the specific training camp where they learned to run. All three factors are required for an accurate prediction.

Features

  • Polyglot Architecture: Complete decoupling of network routing and mathematical computation.
  • High-Speed gRPC Boundary: Sub-millisecond communication between the Java Gateway and Python compute node.
  • Reactive I/O: Quarkus Gateway handles concurrent REST ingestion without blocking threads.
  • Live AI Inference: Real-time regression predictions using a custom-trained PyTorch Multi-Layer Perceptron (Auto MPG dataset).
  • Containerized: Fully isolated, production-ready Docker Compose orchestration.

Roadmap

  • Implement robust service discovery for the Gateway API.
  • Add authentication, authorization, and rate limiting to the Gateway.
  • Integrate Kafka for asynchronous, high-throughput message queuing.
  • Implement comprehensive distributed tracing and monitoring with OpenTelemetry.
  • Deploy the entire mesh to a Kubernetes cluster.

About

Distributed microservices architecture for AI inference at the edge

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Contributors