Free sample lesson ยท Enterprise LLM Architecture and Deployment

Request Lifecycle

What happens inside your system from user prompt to the final generated token?

Lesson 1 of the Wondering course Enterprise LLM Architecture and Deployment

From Prompt to Token

A user types a question. Seconds later, words stream back.

Between those two moments sits a chain of infrastructure stages, each with its own job.

This chain is the request lifecycle. Every enterprise LLM system runs it for every single request.

Knowing the order of stages is how you find slow spots and prove the system is production-ready.

The inference pipeline, end to end
  • API gateway: The user prompt enters the system and is authenticated and rate limited.
  • Retrieval: The request is enriched with context from a vector database.
  • Inference engine: The enriched prompt is queued, batched, and passed through the model layers.
  • Post-processing: Output passes through safety filtering and formatting before streaming back.

The API Gateway Front Door

The lifecycle begins at the API gateway.

Think of it as the front door of your system. Nothing reaches the model without passing through it.

It does two things first: authentication, which checks who is calling, and rate limiting, which caps how many requests a caller may send.

Gateway checks before the model
  • User prompt: The prompt enters the system via the API gateway.
  • Authenticated?: The gateway checks who is calling.
  • Within rate limit?: The gateway caps how many requests a caller may send.
  • Request validated: The request continues into preprocessing.
  • Request refused
  • Yes
  • No
  • Yes
  • No

Rate limiting is not about fairness alone. It protects system stability when traffic spikes.

Preprocessing With Retrieval

Once validated, the request often enters a preprocessing stage.

Here the raw prompt is enriched with context pulled from a vector database. This is Retrieval-Augmented Generation, or RAG.

The model itself does not change. What changes is the prompt it receives.

So the same question can produce very different answers depending on what retrieval attached to it.

Before and after retrieval
  • Raw prompt
  • Enriched prompt

Inside the Inference Engine

The enriched prompt now reaches the inference engine, where the model processes the tokens.

Three things happen inside, in order.

The request is queued. Then it is batched with other requests to optimize throughput. Then it is passed through the neural network layers.

Only after that does the model begin generating response tokens.

Three stages inside the engine
  • Queued: The request waits inside the inference engine.
  • Batched: It is grouped with other requests to optimize throughput.
  • Network layers: The batch is passed through the neural network layers.
  • Generation: The model generates the response tokens.

Why Batching Exists

Batching is the stage newcomers find most surprising.

Your request is deliberately grouped with other users' requests before the model runs.

The reason is throughput: processing many requests together uses the hardware far more efficiently than one at a time.

But queuing and batching add waiting time. Throughput and latency pull against each other here.

Why make a request wait on purpose?

Post-Processing The Output

Generated tokens do not go straight to the user.

They pass through a post-processing layer first.

This layer handles safety filtering and formatting. Only then is the response streamed back to the user.

Streaming is why answers appear word by word rather than all at once.

After the model generates
  • Tokens generated: The model produces the response tokens.
  • Safety filtering: The post-processing layer filters the output for safety.
  • Formatting: The response is formatted for delivery.
  • Streamed back: The response is streamed back to the user.

Every Stage Has A Cost

Latency is not created in one place. It accumulates across the whole path.

The gateway spends time on authentication and rate limiting. Preprocessing spends time querying the vector database. The engine spends time queuing and batching. Post-processing spends time filtering and formatting.

This is why tracing the lifecycle matters: a slow answer may have nothing to do with the model itself.

Where time is spent

Security At Each Boundary

Security is not a single wall at the edge of the system.

The gateway controls who may call. Post-processing controls what may leave.

Each stage must meet the security and performance requirements of enterprise-grade deployment.

Miss one boundary and the whole path is exposed, no matter how strong the others are.

Two control points, two jobs
  • API gateway
  • Post-processing

Why Enterprises Trace This Path

Enterprise deployments promise customers specific response times through service level agreements.

You cannot commit to a number you cannot locate. Tracing the lifecycle tells you which stage owns the delay.

It also proves each stage meets the security requirements a customer-facing service demands.

The pipeline is the proof that your infrastructure is built for production.

What the lifecycle proves
  • Latency bottlenecks: Tracing tells you which stage owns the delay.
  • Service level agreements: Enterprises promise customers specific response times.
  • API gateway: Handles authentication and rate limiting at the start.
  • Inference engine: Queues and batches requests before the network layers.
  • Post-processing: Filters and formats output before streaming back.
  • Security requirements: Each stage must meet enterprise-grade requirements.

Check yourself

Rate limiting at the API gateway helps protect system stability during traffic spikes.

  • True
  • False

Answer: True

Correct. Rate limiting caps requests from a caller, reducing overload when traffic increases. It is not only a fairness mechanism.

A vector database can supply _____ during preprocessing, while the _____ remains unchanged. The enriched prompt may therefore produce a different answer.

Answer: A vector database can supply retrieved context during preprocessing, while the model remains unchanged. The enriched prompt may therefore produce a different answer.

Retrieval changes the information included in the prompt, not the underlying model. Different retrieved context can lead to different outputs for the same question.

Why are requests batched before passing through the neural network layers?

  • To improve hardware efficiency and throughput
  • To add retrieved context to the prompt
  • To authenticate the caller
  • To stream tokens before inference begins

Answer: To improve hardware efficiency and throughput

Batching groups requests so hardware can process many of them efficiently, improving throughput. The trade-off is that queuing and batching can add waiting time and increase latency.

Keep going

This is lesson 1 of 13 in Enterprise LLM Architecture and Deployment. Next up:

  1. Model Sizing
  2. Routing Mechanisms
  3. The Mathematics of MoE Routing
  4. Latency Metrics
  5. Throughput Defense

Start this course free

Wondering turns any topic into short lessons you can read, watch, or listen to, with practice questions and an AI tutor.