Backend for an AI image generation platform
Long-running AI image jobs with live progress, credits and plans, storage and print-ready output. Arya designed the backend architecture and built the services that orchestrate every job.
- Type
- AI image generation platform
- Role
- Backend architect and engineer
- Stack
- Node.js, Express, Fastify, Server-Sent Events, WebSockets, Redis, MongoDB, AWS EC2, Amazon S3, CloudFront, NGINX, Let's Encrypt (Certbot), AWS Systems Manager, Third-party AI model APIs, Shopify webhooks
Context
The problem: slow AI jobs and costly model calls
The product let customers generate images from text, edit them, upscale and stylise them, inpaint parts of an image and prepare files for print. It served a web app, a mobile app and a customer portal.
These jobs take time and call paid third-party models. Users needed to see progress instead of a frozen screen, credits and plans had to be enforced, and every image had to be stored and delivered reliably.
Why live progress and credit control mattered
Slow AI jobs with no feedback feel broken, and users leave.
Paid model calls that are repeated or not controlled get expensive quickly. Print customers need files at the correct resolution, not screen-quality images.
Arya’s role
Arya designed the backend architecture and built the services that orchestrate every generation and processing job.
What Arya built
Inside the AI image generation backend
An API server
Node.js, with routing, rate limiting and request validation.
A generation service
It orchestrates requests to text-to-image, image-editing and specialised models (upscale, inpaint), streams progress to the client, and handles retries and errors.
Live progress
Over Server-Sent Events and WebSockets, with distinct events for a preview image, the final image, done and error.
An image processing service
Upscaling, stylisation, inpainting, print preparation targeting 300 DPI with automatic upscaling, and thumbnails.
A user and credit service
Sessions, credit balance and plans, customer data and collections, kept in sync with Shopify through customer and subscription webhooks.
Data and cache
MongoDB for users, sessions, generation logs, image metadata and collections. Redis for session data, temporary generation state, rate limiting and frequently read data.
Storage and delivery
Generated images in S3, served through CloudFront URLs.
Infrastructure
EC2 application servers behind NGINX as a reverse proxy, TLS through Let's Encrypt (Certbot), security groups, configuration and secrets in AWS Systems Manager, and application logs with error alerts. The API layer is stateless, so it can scale out.
Engineering
Key decisions
Evaluate before building.
More than 90 AI models were evaluated before choosing the ones the platform calls.
Stream instead of making users wait.
Progress events go to the client as soon as the model reports them, so the interface always shows what is happening.
Cache before calling a model again.
Redis holds temporary state and recent results, which avoids repeating a paid model call for the same work.
Enforce credits on the server.
Balances and plans are checked in the backend, not the app, and stay in step with subscription changes from Shopify.
Keep the API stateless.
Session and job state live in Redis and MongoDB, so any server can handle any request.
Results
Results for the AI image platform
- Long AI jobs show live progress instead of a blank wait.
- Repeated work is served from cache, not sent to a paid model again.
- Customers get print-ready files without preparing them by hand.
- Credits and plans are enforced in one place and match subscription status.
- Images are stored once and delivered fast through a CDN.
Architecture
The full system
For engineering readers. Everything in the drawing is described in the text above.
Client apps call a stateless Node.js API layer, which orchestrates third-party models, streams progress back, and stores output in S3 behind CloudFront. Capabilities are shown by name; internal endpoint paths are left out.
Stack
Technology
- Node.js
- Express
- Fastify
- Server-Sent Events
- WebSockets
- Redis
- MongoDB
- AWS EC2
- Amazon S3
- CloudFront
- NGINX
- Let's Encrypt (Certbot)
- AWS Systems Manager
- Third-party AI model APIs
- Shopify webhooks
For your business
Similar problems Lubili can solve
Adding AI features to an existing product, orchestrating model APIs, background jobs with live progress, usage and credit systems, and media storage and delivery.
Built in an earlier software engineering role. Company and client details are kept confidential.
Building an AI feature that has to work for real users?
Tell us what you are building and where it gets stuck. Every message gets a personal reply.
Free. No obligation. You get a one-page written summary.