<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Building at Scale | Nishchay Jain]]></title><description><![CDATA[Building at Scale | Nishchay Jain]]></description><link>https://nishchayjain.hashnode.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1593680282896/kNC7E8IR4.png</url><title>Building at Scale | Nishchay Jain</title><link>https://nishchayjain.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Sun, 20 Sep 2026 09:49:26 GMT</lastBuildDate><atom:link href="https://nishchayjain.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The Architect's Guide to Maximising Token Efficiency in LLM Applications
]]></title><description><![CDATA[If you're shipping an LLM feature right now, there's a good chance token bloat is quietly eating your margins and nobody's noticed yet.
Tokens are what you pay for — every character you send in, every]]></description><link>https://nishchayjain.hashnode.dev/the-architect-s-guide-to-maximising-token-efficiency-in-llm-applications</link><guid isPermaLink="true">https://nishchayjain.hashnode.dev/the-architect-s-guide-to-maximising-token-efficiency-in-llm-applications</guid><category><![CDATA[llm]]></category><category><![CDATA[System Design]]></category><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[software development]]></category><category><![CDATA[Software Engineering]]></category><dc:creator><![CDATA[Nishchay Jain]]></dc:creator><pubDate>Mon, 06 Jul 2026 11:11:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a4b7f43660135af5918fa07/4ebb2b12-95ff-40c5-8791-68c45d688ded.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you're shipping an LLM feature right now, there's a good chance token bloat is quietly eating your margins and nobody's noticed yet.</p>
<p>Tokens are what you pay for — every character you send in, every character the model sends back. In a demo, that's pocket change. At production scale, serving thousands of users a day, sloppy token usage is the difference between a feature that pays for itself and one that quietly bleeds money every month.</p>
<p>This guide walks through the architectural patterns, prompt techniques, and system designs that actually move the needle on token efficiency — without gutting output quality.</p>
<hr />
<h2>1. Why This Actually Matters</h2>
<p>Three things are at stake here, and they compound:</p>
<ul>
<li><p><strong>Cost.</strong> Providers charge per million tokens, and output tokens are typically priced several times higher than input tokens. Careless generation costs more than careless retrieval.</p>
</li>
<li><p><strong>Latency.</strong> Time-to-first-token and total generation time both scale with token volume. Fewer tokens, faster responses — it's that direct.</p>
</li>
<li><p><strong>Accuracy.</strong> Even with a 128k or 1M token context window, stuffing it full doesn't help. Models get measurably worse at retrieving information buried in the middle of a long context — the so-called "lost in the middle" effect. More context isn't free, even when it fits.</p>
</li>
</ul>
<hr />
<h2>2. Stop Stuffing the Context Window: Smarter RAG</h2>
<p>Retrieval-Augmented Generation is how most teams give an LLM knowledge it wasn't trained on. The problem is the naive version of it: grab the top-k vector search results, dump them straight into the prompt, and hope for the best. That's usually where the token waste starts.</p>
<p>A better pipeline compresses before it generates:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6a4b7f43660135af5918fa07/690170ec-a839-4fa4-aa4c-663184f624f3.png" alt="" style="display:block;margin:0 auto" />

<p>Two changes do most of the work:</p>
<p><strong>Chunk by meaning, not by character count.</strong> Splitting text every 500 characters guarantees you'll cut sentences in half, and the model burns tokens trying to make sense of a fragment. Chunk along sentence or paragraph boundaries instead.</p>
<p><strong>Re-rank before you generate.</strong> Use a cheap embedding model to pull back 20 candidate chunks, then run those through a cross-encoder (Cohere Rerank and BGE-Reranker are both solid choices) to narrow it down to the 3 that actually matter. Only those go to the expensive model.</p>
<hr />
<h2>3. Say Less: Prompt Compression</h2>
<p>The way you phrase a prompt has a real cost attached to it.</p>
<p><strong>Cut the pleasantries.</strong> The model doesn't care about "please" or "could you kindly."</p>
<ul>
<li><p><em>Verbose:</em> "Could you please analyze this JSON and tell me what the user's name is? Thank you!" — 17 tokens</p>
</li>
<li><p><em>Direct:</em> "Extract user name from JSON." — 6 tokens</p>
</li>
</ul>
<p><strong>Be deliberate with few-shot examples.</strong> They improve output quality, but you pay for them on every single call. If you're leaning on a large few-shot prompt to get consistent behavior, that's usually a sign you should fine-tune instead. A fine-tuned <strong>GPT-5.4 nano</strong>, or an open-weight option like <strong>Llama 4 Scout</strong>, can match a much larger model's performance on a narrow task with zero examples in the prompt — which adds up fast at volume. (Worth keeping an eye on: OpenAI's Luna model, part of the GPT-5.6 preview, looks like it'll be an even cheaper option once it's generally available — just not something to build on yet.)</p>
<hr />
<h2>4. Controlling the Expensive Half: Output Tokens</h2>
<p>Output tokens usually run 3-5x the cost of input tokens, so how much the model says back matters more than how much you send in.</p>
<p><strong>Force structured output.</strong> Don't let the model narrate when it should just answer.</p>
<blockquote>
<p><strong>Tip:</strong> Use JSON mode or function calling with a strict schema, every time you're extracting data rather than having a conversation.</p>
</blockquote>
<pre><code class="language-json">// Instead of:
// "Here is the information you requested. The user's name is John and he is 30 years old." (20 tokens)

// Force this:
{"name": "John", "age": 30} // 9 tokens
</code></pre>
<p><strong>Use stop sequences.</strong> Cut generation off the moment the task is done. Generating a Python function? Set <code>stop=["\n\ndef", "```"]</code> so the model doesn't keep going and generate test cases nobody asked for.</p>
<hr />
<h2>5. Semantic Caching: Don't Pay for the Same Answer Twice</h2>
<p>Traditional caching falls apart with LLMs because people rarely phrase things identically — "How do I reset my password?" and "forgot my password, help" are the same question to a human, but not to a string-match cache.</p>
<p>Semantic caching fixes this by comparing embeddings instead of exact strings:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6a4b7f43660135af5918fa07/70b9ac59-169d-4a62-b2d2-519c7eec05ae.png" alt="" style="display:block;margin:0 auto" />

<p>Wire this up with a vector database like Redis or Pinecone, and repetitive queries — FAQs, onboarding questions, common coding asks — stop touching the LLM at all.</p>
<hr />
<h2>6. Model Routing: Match the Model to the Job</h2>
<p>Not every request needs your biggest model. A quick classification step — using something fast and cheap like <strong>GPT-5.4 nano</strong> or <strong>Claude Haiku 4.5</strong> — can sort incoming queries by difficulty before anything hits the expensive model.</p>
<ul>
<li><p>Simple task (formatting, pulling a date out of text)? Route to the cheap model.</p>
</li>
<li><p>Genuinely hard task (writing a complex SQL query, multi-step reasoning)? That's when you reach for <strong>GPT-5.5</strong> or <strong>Claude Sonnet 5</strong>.</p>
</li>
</ul>
<p>Most production traffic skews simpler than teams expect — this one change alone often cuts costs more than any prompt optimisation does.</p>
<hr />
<h2>Conclusion</h2>
<p>None of this is about starving your model of context — it's about being precise instead of lazy with it. Re-rank before you generate. Enforce schemas instead of letting the model ramble. Cache what's already been answered. Route simple work to cheap models. Do all four, and you'll cut infrastructure spend meaningfully while making the product faster for the people actually using it.</p>
<p>As LLM features move from prototype to production, this kind of token discipline is quickly becoming table stakes for backend and full-stack engineers — not a nice-to-have.</p>
]]></content:encoded></item></channel></rss>