AI · architecture walkthrough

In every AI product, the backend is the real hero.

The model gets the headlines. But what makes an AI feature fast, affordable and reliable is everything around it. Type any question into the app below, then scroll through the nine steps at your own pace and see exactly what each box does with it.

type a question below and follow it through the system ↓
AI-POWERED PLATFORM · STEP 1 / 9
client · priyanshu.dev/ask
Type a question and press Send. Nothing is answered — you’ll see how it flows.
REQUEST PATH
Client
browser / app
API gateway
auth, routing
Rate limiter
token budget · Redis
Semantic cache
Redis
Orchestrator
Spring Boot
Postgres
sessions, users
Vector DB
pgvector
LLM gateway
retry · breaker · fallback
ModelAI
the AI
Stream
SSE to client
ASYNC · AFTER THE RESPONSE
Queue
Kafka
Usage & cost
per feature
Feedback
evals
INGESTION · OFFLINE
New docs
uploads, CMS
Embed workers
chunk + embed
→ Vector DB
idempotent upsert
01

A question arrives

Auth first, then a per-user token budget checked in Redis. One runaway script can burn a month’s AI bill — the limiter is the first line of defence.

Spring Security · Redis Lua · 429 + Retry-After
02

Check the semantic cache

Similar questions often have the same answer. A cache hit returns in milliseconds and never touches the model — the cheapest AI call is the one you don’t make.

Redis · embedding similarity · TTL
03

Orchestrate the request

A Spring Boot service loads the user’s session and context from Postgres, decides what to retrieve, and which tools the model may call.

Spring Boot · Postgres · tool registry
04

Retrieve only what matters

Vector search finds the few chunks relevant to this question. Short, grounded prompts are faster, cheaper and hallucinate less.

pgvector · top-k · metadata filters
05

Call the model — safely

Timeouts, retries with backoff, a circuit breaker, and a cheaper fallback model when the main one struggles. The model is one box; the safety net around it is backend.

Resilience4j · backoff · fallback routing
06

Stream it back

Tokens flow back over Server-Sent Events as they’re generated, so the first word appears long before the answer is finished.

SSE · backpressure · cancellation
07

Do the bookkeeping later

Token usage, cost per feature and user feedback go onto a queue. The user never waits for analytics.

Kafka · consumers · idempotent writes
08

Keep knowledge fresh

New documents go through a queue to embedding workers. Jobs are idempotent, so a retry never creates duplicate vectors.

queue · workers · upsert by content hash
09

Now count the boxes

Sixteen boxes on this diagram. One of them is the model. Almost everything that makes the product fast, cheap and reliable is backend.

that’s the job I do

Built in production

Voice agents: same story, tighter deadline

I’ve built an ASR → LLM → TTS pipeline to automate support calls. In voice, every stage has to stream into the next — silence on a phone call feels like a bug.

1 · LISTEN
Speech → text
Stream audio, detect end of turn
2 · THINK
LLM + context
Account lookup, intent, answer
3 · SPEAK
Text → speech
Speak the first sentence early
ESCAPE HATCH
Hand off to a human
Low confidence or frustrated caller

Concepts I work with

Embeddings & vector searchSemantic cachingToken budgetsRetries & fallbacksStreaming (SSE)Structured outputsTool callingASR / TTSEvals & guardrails
← Back to the LabBuilding an AI feature? Let’s talk →