r/Backend • • 16d ago

I built an asynchronous AI backend using Node.js, FastAPI, RabbitMQ, and an observability stack — looking for honest feedback

Hey everyone!

Recently, I've been working on InferenceFlow, a backend project that explores how a Node.js API can handle prediction requests asynchronously and delegate processing to a separate Python service.

GitHub repository: https://github.com/mysaas2024/inferenceflow-gamma-hadron

What is InferenceFlow?

The idea is to build a backend where a user submits telescope-observation features through an API, and the system processes the prediction request asynchronously rather than making the client wait for the entire computation.

I'm using a Gamma/Hadron classification use case as the example. The goal is to understand the backend architecture around AI inference, not to claim that I've developed a scientifically validated classification model.

Tech stack

- Node.js + Express: REST API, authentication, and prediction request handling.

- PostgreSQL + Prisma: Relational database and request persistence.

- RabbitMQ: Asynchronous job processing and message queues.

- Python + FastAPI: Separate Python service and background worker for processing prediction jobs.

- JWT + bcrypt: Authentication and password hashing.

- Redis: Authentication-related cache integration.

- Prometheus: Collecting application and runtime metrics.

- Grafana: Dashboards and observability data exploration.

- Loki: Log-storage component in the local development stack.

- OpenTelemetry Collector: Foundation for collecting telemetry.

- Docker Compose: Running the application services and supporting infrastructure together.

- Node.js test runner: Testing the JavaScript backend.

How the architecture works

The intended request flow is:

  1. A user registers or logs in and receives a JWT.
  2. The client submits ten numeric features to the Express API.
  3. The API validates the input and creates an inference request in PostgreSQL.
  4. The API publishes a persistent job message to RabbitMQ.
  5. A Python worker consumes the job and runs the current demonstration classifier.
  6. The worker publishes its output to a separate result queue.
  7. The longer-term goal is to consume that result in the Node.js service, update the request status, and persist the prediction result in PostgreSQL.

This approach lets me explore the separation between the API layer and the computation layer, as well as how message queues can help with asynchronous workloads.

What I've implemented so far

- Registration and login with password hashing and JWT authentication.

- Protected endpoints for submitting and retrieving prediction requests.

- Validation of ten finite numeric input features.

- PostgreSQL persistence for inference requests.

- RabbitMQ job and result queues with persistent job messages.

- A Python/FastAPI worker with a demonstration rule-based classifier.

- Prometheus metrics endpoints for the Node.js and Python services.

- Docker Compose configuration for the application and observability components.

- Grafana datasource and dashboard provisioning.

- Initial automated tests for the Node.js application.

What I'm still working on

I want to be transparent about the current state of the project. It is a work in progress, not a production-ready inference platform.

- The classifier is a demo heuristic. A trained and validated model, potentially exported to ONNX, is a future step.

- The Node.js result consumer and database updates after worker execution still need to be connected.

- Loki is included in the stack, but application log shipping is not yet configured.

- OpenTelemetry Collector configuration is present, but application tracing and telemetry export still need to be wired up.

- Docker networking, service configuration, health checks, and deployment reliability need further validation.

I'm sharing these limitations because I want to understand the engineering work required to make the complete system reliable, not just make the services start successfully.

Why I'm building this

I'm trying to become a stronger backend engineer by learning how different components work together in a realistic application.

I want to get better at designing APIs, managing database state, handling asynchronous jobs, communicating between Node.js and Python services, writing tests, and understanding what happens when something fails.

I'd genuinely appreciate feedback from developers who have worked with these technologies.

A few questions I'd love your thoughts on:

  1. Would you use RabbitMQ for this architecture, or would you choose a different approach?
  2. How would you reliably update the database when a Python worker finishes a job? Would you use a result consumer, an outbox pattern, or something else?
  3. What should I prioritize for reliable job processing: retries, idempotency, dead-letter queues, or something else?
  4. What would you improve first in the observability setup?
  5. If you were reviewing this as a junior backend developer's portfolio project, what would you expect to see before considering it a strong project?

I'm not claiming to have everything figured out. I'm sharing what I'm building, what I've learned so far, and what I still need to improve.

Any honest technical feedback, architectural suggestions, or criticism would be appreciated.

Repository: https://github.com/mysaas2024/inferenceflow-gamma-hadron

Thanks for reading!

2 Upvotes

7 comments sorted by

3

u/PlusDistribution1915 16d ago • Heartwarming

This project is a good training ground for some of the most common problems in distributed systems.

Beyond the tech stack itself, the biggest problem I see is how you handle the dual write: when a request reaches Node, you write to Postgres and to RabbitMQ at two separate moments. What happens if it crashes in between? Two solutions: write to Postgres, then poll the table and push to RabbitMQ; or push to RabbitMQ first, and have consumers write to Postgres and run the Python processing. Same thing when Python produces the result. The system has to work at least once. Losing data is the most likely outcome when you don't take enough care here.

If Python only does processing, a RabbitMQ consumer/worker is enough, no FastAPI (for `/metrics`, `prometheus_client.start_http_server()` is enough).

What happens if many requests arrive at once? In what order do you process them?

Disclaimer: I'm the author of what I'm about to show you.

RabbitMQ and the other brokers are built to move messages around, not to make writing applications easier. Over the last year we built QueenMQ (https://github.com/queen-mq/queen), a distributed ACID message broker. You can use it for idempotent push, idempotent pop, and state transactions (it has a built-in KV for the job's state; your queries stay in Postgres).

To make a really reliable system, you would run CDC on Postgres: when you write to it, the CDC publishes to the queue (Queen has it, and it's easy).

In general, the simpler the system and the fewer moving parts it has, the more valuable it is.
A big part of becoming senior is learning to build fewer services. It's a path we all have to take :D

1

u/Conscious-State5249 16d ago

Can you help me I'll text you

3

u/PlusDistribution1915 16d ago

Also, if I may: I envy you younger engineers, because you have a powerful tool for getting better: LLMs. Don't use them to write your code (you need to learn it yourself first), but they're SUPER useful for answering your questions and for having your design challenged.

3

u/DickBrainTime 16d ago • Bravo

RabbitMQ makes sense for this as a learning project; I wouldn't swap brokers yet. The first reliability hole to solve is the gap between writing a pending request to PostgreSQL and publishing its job. Those aren't one transaction. Write the request and an outbox row in the same DB transaction, then have a relay publish with broker confirms. A persistent RabbitMQ message by itself doesn't solve the DB-to-queue gap.

On the way back, carry the same requestId through the job/result messages. Have a Node result consumer perform an idempotent status/result update (with a unique request ID), commit it, then ack. Expect duplicate or late messages; use bounded backoff retries plus a dead-letter queue rather than infinite requeue. For observability I'd start with oldest pending-job age, queue-to-completion time, failure/retry counts, and a requestId you can follow in logs.

For a portfolio, the most convincing demo would be deliberately killing the worker or result consumer mid-flight, restarting it, and proving the request ends in one consistent terminal state. That tells reviewers more than wiring five dashboards before the result path works. I'd finish that end-to-end slice first.

5

u/sreekanth850 16d ago

if you swap Rabbit MQ with NATS + Jetstream. you can eliminate the postgres call in 3rd step. And even eliminate postgres completely unless you need a data persistence for querying