Running Example
Each pattern is illustrated through a coding assistant app with a Python backend (assistant.py) and JavaScript frontend. The backend setup is shared across all patterns:
Pattern 1: Don’t let your UI become the bottleneck
The GPU approach: When inference is slow, elaborate loading states are a feature. You might incorporate animated progress trees, character-level streaming effects, and detailed visualizations to give users something to look at while the model thinks. The Cerebras approach: At Cerebras speeds, if the frontend is doing significant work to render each streaming chunk, the interface may spend more time rendering than the model spends generating. The model finishes before the UI catches up. For the coding assistant, this surfaces in the editor’s streaming display. If the UI updates every time new tokens arrive, it can’t keep up with Cerebras token rates and the display visibly lags. A simple fix is to batch incoming tokens and update the screen on a short timer (e.g. every 50ms) instead of on every event:- Agent progress trees — detailed per-step visualization of tool calls and reasoning. At GPU speeds, this gives users something to follow while waiting for a response. At Cerebras speeds, steps complete so quickly that the UI flicker can be more disorienting than helpful. A simpler “working…” state that resolves to a final result is often better.
- Per-event streaming animations — character-level fade-ins or cursor effects that fire on every SSE event. Beyond rendering overhead, these will behave unexpectedly on Cerebras because each event may carry several tokens, not one. See Pattern 3 for details.
- Infrastructure overhead — code that runs between your app and the Cerebras API (authentication, logging, data formatting) adds up in ways that don’t matter at GPU speeds, but can become noticeable when inference is fast. If you’re not seeing the performance you expect, measure the full request cycle, not just the model call.
Pattern 2: Synchronous AI in the request path
The GPU approach: When an LLM call takes several seconds, you can’t afford to make the user (and the server) wait that long in a normal request/response cycle. So you put it on a job queue, hand the user a task ID, and poll until it’s done. That means standing up a worker, a queue, state tracking, and a polling or webhook layer — all to handle what’s fundamentally one function call. The Cerebras approach: Make the LLM call directly in the request handler and return the result synchronously, the same way you’d call a database or external API:Pattern 3: Use streaming selectively
The GPU approach: Streaming is often treated as a best practice for AI applications, but it exists to reduce time to first token (TTFT) — the delay between sending a request and seeing the first word of a response. When inference is slow, even a partial response appearing quickly feels better than a blank screen, so streaming becomes the default for all AI calls. The Cerebras approach: Stream selectively based on response length:- Short responses (under ~200 tokens): The complete response arrives so quickly that streaming offers little perceptual benefit. A synchronous call that returns in under a second often feels faster than watching a brief response stream in word by word.
- Long responses (200+ tokens): Streaming still meaningfully improves the experience. The user sees content immediately rather than waiting for a full response to generate.
generate() function handles both:

