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.
- 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).
- Clone the repository.
- Deploy the mesh using Docker Compose:
docker compose up --build -d
- Monitor the startup logs:
docker compose logs -f
If you prefer to run the services bare-metal for debugging without Docker, you can start the nodes individually.
- Start the Inference Node (Python)
Ensure you have the required artifacts (auto_mpg_weights.pthandauto_mpg_scaler.pkl) in theartifacts/auto_mpgdirectory.The gRPC server will start on port 50051.cd inference_service uv run src/main.py - Start the Gateway API (Java)
In a separate terminal, launch the Quarkus dev server.The REST API will be available on port 8080.cd gateway_api ./mvnw clean quarkus:dev
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
}'The neural network requires 7 specific features to accurately predict efficiency.
- Physical Metrics:
cylinders,displacement,horsepower,weight, andacceleration. 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.
- 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.
- 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.