Lubili
Engineering work

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.

Built by Arya Shrimali, founder of Lubili
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
AI image platform overviewApps call the API layer, which sends requests to third-party AI models and streams live progress back to the app. Finished images are uploaded to S3 and delivered to the apps through the CloudFront CDN.Client apps3 front endsAPI layerNode.jsAI modelsThird-party APIsAmazon S3Image storageCloudFrontCDNlive progressrequestsoutputimage URLs
The flow in one picture. The full architecture is further down the page.Scroll sideways or pinch to zoom

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

  1. Evaluate before building.

    More than 90 AI models were evaluated before choosing the ones the platform calls.

  2. 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.

  3. Cache before calling a model again.

    Redis holds temporary state and recent results, which avoids repeating a paid model call for the same work.

  4. 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.

  5. 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.

AI image platform backend architectureA web app, a mobile app and a customer portal call a stateless Node.js API layer over HTTPS. The API layer has four services: the API server for routing, rate limiting and validation; the generation service, which orchestrates third-party text-to-image, image-editing and specialised models and streams progress back to the clients over Server-Sent Events and WebSockets, with preview, final, done and error events; image processing for upscaling, stylisation, inpainting, print preparation and thumbnails; and the user and credit service. Processed images are uploaded to S3 and served through CloudFront. MongoDB stores users, sessions, generation logs, image metadata and collections. Redis holds session data, temporary job state, rate limits and frequently read data. The infrastructure is EC2 behind NGINX, with Let's Encrypt TLS, security groups, AWS Systems Manager for configuration and secrets, and logs with alerts.CLIENT APPSWeb appMobile appCustomer portalStream eventsSSE / WebSocketimage (preview)image (final)doneerrorAPI LAYERNode.jsAPI serverExpress / FastifyRouting, rate limitingRequest validationGeneration serviceOrchestrationStreams progress to clientsRetries and errorsImage processingOutput pipelineUpscale, stylise, inpaintPrint prep, thumbnailsUser and credit serviceAccountsSessions, credits, plansCollectionsHTTPS / RESTSSE / WebSocketAI MODEL LAYERThird-party APIsText to imageImage editingSpecialisedUpscale, inpaintModel requestsProgress +resultsSTORAGE + DELIVERYAmazon S3Generated imagesCloudFrontCDNPublic image URLsto the client appsUpload outputDATA AND CACHEMongoDBApplication dataUsers, sessionsGeneration logsImage metadataCollectionsRedisCacheSession dataTemporary job stateRate limitingHot dataCAPABILITIESGenerationstreamedEnhancementupscale, styliseEditinginpaint, reframePrint prep300 DPI, upscaleImage librarythumbnails, uploadsUsers and creditssessions, plansCommerce webhookscustomer, subscriptionINFRASTRUCTUREStateless API layerEC2app serversNGINXreverse proxyLet's EncryptTLS (Certbot)Security groupsand HTTPSSystems Managerconfig, secretsLogs and alertserror alerts
Clients never wait on a blank screen: the generation service streams progress back while third-party models do the work.Scroll sideways or pinch to zoom

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.