<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Sagar Thakkar - Writing</title><description>Notes on distributed systems, AI agent architecture, and engineering leadership.</description><link>https://sagarthakkar.com/</link><item><title>The AI Loan Officer Exists. The Hard Part Is Everything Around It.</title><link>https://sagarthakkar.com/blog/async-ai-decisioning/</link><guid isPermaLink="true">https://sagarthakkar.com/blog/async-ai-decisioning/</guid><description>AI loan decisions are lifecycles, not responses: async intake, queued workers, human-review loops, and an audit trail regulators can trust - end to end.</description><pubDate>Wed, 22 Jul 2026 00:00:00 GMT</pubDate><content:encoded>Right now, in a thousand companies, the same architecture is being drawn on a whiteboard. User hits an endpoint, endpoint calls the model, model returns the answer. Request in, intelligence out. It is how we have wired software for thirty years, so it is how everyone is wiring AI.

For a chatbot, fine. But the AI systems banks actually want, the ones that *decide* things, do not behave like responses. The concrete case this post is built on is an **AI loan officer**: a lending model that reads an application and returns **Approved**, **Denied**, **Mismatch**, or **Query**.

Three facts break the request-response picture at once. The verdict takes **about 8 minutes**, and nothing in the web stack will hold a connection that long. Two of the four verdicts are not answers at all: they are detours through a human that come *back*. And in a regulated business, the decision is not finished when it is delivered. You must be able to defend it, with the exact model that made it, years later.

A response is a moment. **A decision is a lifecycle.** It starts before the model runs and stays alive long after. Architect for the moment and you get a demo. Architect for the lifecycle and you get a production system. Here is the lifecycle version, end to end: four moves I think of as the lifecycle four, and the design I would defend in a review.

## The engineering problem: one slow model, hundreds of decisions a day

The constraint takes one line. Inference runs about 8 minutes. The callers operate on connection timescales of seconds: a finance team uploading batches of 300, customer apps trickling in singles. Nobody needs the verdict instantly. They need the *system* to take the request instantly and never lose one.

So the engineering problem is not &quot;make the model faster&quot;. It is this: **turn one slow model into a decisioning system that absorbs any load, scales out, survives failures, and can prove every verdict.** That is a known pattern, and it starts with one rule:

&gt; **Never make the caller wait. Accept the request, return an ID in milliseconds, process in the background, notify when the verdict lands.**

Everything else in this design is a consequence of that one rule. Drawn out, the whole system looks like this:

![Async AI decisioning architecture: sources to gateway to ingestion to queue to autoscaled workers, then a decision router with four outcomes, two of which loop back](/blog-assets/async-ai-decisioning-architecture.svg)

*Requests enter once. Verdicts leave four ways, and two of those ways loop back in. The sections below walk it left to right.*

## Walking the flow: from loan application to AI verdict

### Two kinds of traffic, one front door

The finance team sends bulk uploads: bursty, hundreds at once, nobody watching a spinner. The customer apps send single applications in a steady trickle. The person on the other end cares about the *acknowledgement*, not the verdict. Different shapes, same door. One gateway handles auth, validation and rate limiting, so no downstream service reinvents them. The interesting part is what happens in the milliseconds after that door.

### The accept-fast layer

The ingestion API is where the async promise is kept. For every request it validates the payload. Then it deduplicates on an **idempotency key**, because a retried upload must never create two loan decisions. It parks the documents in object storage, writes `status = RECEIVED` to the state DB, and pushes a message onto the queue. Then it returns **`202 Accepted` with an `application_id`**. Total connection time: milliseconds. The caller polls or gets a callback later.

That idempotency key is not a nice-to-have. Finance teams re-upload files. Mobile apps retry on flaky networks. Without dedup, &quot;the model approved this loan twice&quot; becomes a sentence you say to an auditor.

### The queue is the shock absorber

The queue is the least glamorous and most important box in the diagram. It converts unpredictable inbound load into a steady, controllable workload. A burst of 1,000 requests does not crash anything. The queue just gets deeper, and workers drain it at their own pace. If you remember one component from this article, make it this one.

### Workers: your existing AI app, multiplied

Each worker pulls one message, runs the model for about 8 minutes, and writes the verdict back. Three properties are non-negotiable. Workers are **stateless and containerised**, so N copies run happily. They **autoscale on queue depth**, not CPU, because queue depth is the only metric that measures actual backlog. And they are **idempotent**: a worker dying mid-run just means the message reappears and another worker finishes the job.

### How do you scale a slow AI model? The capacity maths

One worker does 60 / 8 = **7.5 requests an hour**, about 180 a day around the clock. You never make a single request faster. You run more of them in parallel, and throughput scales linearly:

- Workers needed = `(daily volume x 8 min) / available minutes`
- At **500 requests/day**, running 24x7: `500 x 8 / 1440 = about 3 workers` as the baseline. Autoscale to about 10 for bursts, and toward zero overnight so you stop paying.

For a bank, that last property is the quiet headline. The marginal cost of a decision is a few worker-minutes of compute, and idle hours cost nothing. The full queueing maths, from Little&apos;s Law to burst sizing, deserves its own post, and it is coming in this series.

## It is not a pipeline. It is a decisioning engine.

This is the part most write-ups skip. The four verdicts are not four labels. They route differently, and two of them are **loops**, not endings:

| Verdict | What happens | Human in the loop? |
|---|---|---|
| **Approved** | Disbursement workflow + notify | No |
| **Denied** | Notify with reason code + audit | No |
| **Mismatch** | Route to an Ops review queue | **Yes, and it loops** |
| **Query** | Request missing info, then **re-enter the pipeline** | **Yes, and it loops** |

`Mismatch` and `Query` are not failures. They go to a human or back to the applicant, get corrected, and are re-enqueued. A request has a *lifecycle*:

```
RECEIVED -&gt; QUEUED -&gt; PROCESSING -&gt; +-- APPROVED  -&gt; DISBURSED
                                    +-- DENIED    -&gt; CLOSED
                                    +-- MISMATCH  -&gt; UNDER_REVIEW  -&gt; (re-queue)
                                    +-- QUERY     -&gt; AWAITING_INFO -&gt; (re-queue)
```

*A decision&apos;s lifecycle: four exits, two of which come back.*

Model this as a state machine from day one. Bolting states onto a boolean later is how systems rot.

There is also an agentic angle here, and it is where this series is heading. The Ops review step is a queue of structured judgements. That makes it a natural seat for a supervised agent. It drafts the review, cites the evidence, and hands the human a decision to approve rather than a case to research. The loops in this diagram are exactly where agentic behaviour earns its keep. Every loop has a defined state, a bounded task, and an audit trail already waiting.

## Audit, explainability, compliance

A lending decision is a regulated act, and this is the section a bank&apos;s leadership will read first. That is why it comes before the failure drills, not after. The audit trail is a first-class citizen of the architecture:

- **Immutable, append-only record** of every decision: reason codes, model version, timestamps.
- **Explainability stored per verdict**: which features drove it. Disputes and regulators will ask.
- **Decision versioning**: any historical call can be defended with the exact model that made it.
- **PII encrypted** at rest and in transit, with strict access control.

None of this is architecture garnish. For a lender it is the difference between an incident and a headline.

## Security notes: the abuse cases to design for

Compliance answers the regulator. Security answers the attacker, and a decisioning system has a specific attack surface:

- **The front door**: authenticated callers only, rate limits per client, schema validation before anything touches storage. Reject early, log the rejection.
- **The model as a target**: inputs are untrusted documents. Malformed or adversarial files take the poison-request path: bounded retries, then the dead-letter queue, never a crash loop.
- **Workers on least privilege**: a worker can read its message, its documents, and write its verdict. It cannot touch another applicant&apos;s data, and it cannot rewrite the audit store&apos;s history.
- **The audit trail as a crown jewel**: append-only by permission, not by convention. If an attacker can edit history, the compliance story above is fiction.

## What happens when a worker crashes mid-decision?

The failure drills, and what the design already does about them:

- **Worker dies mid-run**: the message&apos;s visibility timeout expires, it returns to the queue, another worker retries. Idempotency prevents a double decision.
- **Poison request** that fails every time: retried N times with backoff, then parked in a **dead-letter queue** for a human. It never blocks the line.
- **Traffic burst**: the queue absorbs it, workers scale out, nothing is dropped.

The pattern in all three is the same. Failures are routed, never raised to the caller, and never allowed to stop the line.

**Steal this: the design-review checklist.** Five questions this architecture answers before anyone asks:

- **Worker crashes?** Queue redelivery + idempotency.
- **Poison requests?** Backoff, then dead-letter queue.
- **Sudden bursts?** Queue absorbs, workers autoscale.
- **Cost?** Scale-to-zero. You pay per processing minute.
- **Defend a decision from two years ago?** Immutable audit + model versioning + stored explanations.

## FAQ: AI loan decisioning in practice

**Will AI replace loan officers?**
Not in the systems I build. The model clears the unambiguous cases: clean approvals and clean denials. Mismatch and Query verdicts still route to a human, and the correction feeds back into the pipeline. The job shifts from reading every file to judging the edge cases.

**What is AI loan decisioning?**
It is the full lifecycle around an AI lending verdict: intake, queueing, model inference, verdict routing, human review loops, notification, and an audit trail. The model is one box. The system is the other nine.

**How is this different from AI underwriting?**
AI underwriting scores the risk on one application. AI loan decisioning is the production system wrapped around that scoring: idempotent intake, autoscaled workers, and verdict routing. Add the immutable trail that lets you defend any decision years later. You need both, and this article is about the second one.

## Takeaway

The model was never the hard part. The mistake is architectural, and it is everywhere right now: treating an AI decision as a response when it is a lifecycle. Four moves make the shift, the **lifecycle four**. **Decouple** receiving from processing. **Scale** horizontally on queue depth. **Treat every verdict as a state machine** whose human loops re-enter the pipeline. **Bake in the audit trail** from day one.

The AI loan officer is the easy hire. Wrap it as a lifecycle and it comfortably serves a national finance operation. Wrap it as a response and it never leaves the demo.

*Next in this series: choosing the stack for async AI. SQS vs Service Bus vs Kafka, and when each is the wrong answer.*</content:encoded><category>system-design</category><category>ai-architecture</category><category>fintech</category><category>async-processing</category><category>cloud-native</category></item><item><title>Why Architects Can&apos;t Ignore Knowledge Distillation of Black-Box LLMs</title><link>https://sagarthakkar.com/blog/knowledge-distillation-black-box-llms/</link><guid isPermaLink="true">https://sagarthakkar.com/blog/knowledge-distillation-black-box-llms/</guid><description>Proprietary LLM costs explode at scale. Here&apos;s how to compress frontier models into deployable, cost-effective alternatives you actually control.</description><pubDate>Mon, 29 Jun 2026 00:00:00 GMT</pubDate><content:encoded># Why Architects Can&apos;t Ignore Knowledge Distillation of Black-Box LLMs

Your enterprise just licensed access to a state-of-the-art proprietary LLM. The model is brilliant—frontier-class reasoning, nuanced outputs, enterprise-grade. 

The problem? Cost explodes at scale. API pricing is per-token. Production traffic multiplies the bill. And you have zero visibility into the model&apos;s internals—no weights, no gradients, no fine-tuning hooks.

You&apos;re trapped. You need the quality. You can&apos;t afford the cost. You can&apos;t own the model.

Enter **knowledge distillation for black-box LLMs**—a technique that lets you transfer the reasoning capability of proprietary models into smaller, cheaper, deployable student models you actually control.

## The Problem Black-Box LLMs Create

Proprietary language models (whether from closed-source vendors or API-only providers) dominate the frontier:
- State-of-the-art reasoning and instruction-following
- Managed infrastructure (no self-hosting headache)
- But: closed weights, vendor lock-in, cost-per-token bleeding

The classic distillation path—fine-tuning a student model on teacher outputs—works. But it assumes you can:
1. Label data extensively
2. Run inference on both teacher and student
3. Absorb the cost of teacher inference at massive scale

For black-box APIs, #3 kills the business case. Distillation becomes too expensive.

![Knowledge Distillation Problem-Solution](/blog/knowledge-distillation-black-box-llms/fig-1-problem-solution.png)
*Figure 1: The problem (API costs, no ownership) vs the solution (distilled student models, full control).*

## Knowledge Distillation Without Teacher Access: Proxy-KD

The core insight: **You don&apos;t need internal weights to extract knowledge.**

![Proxy-KD Architecture Diagram](/blog/knowledge-distillation-black-box-llms/fig-2-architecture.png)
*Figure 2: Three-stage Proxy-KD flow — black-box teacher knowledge transfers through open proxy to deployable student model.*

Proxy-KD sidesteps the closed-box problem by:

### 1. Using a Proxy Teacher
Instead of directly distilling from the proprietary model, distill from an open proxy that mimics its behavior. The proxy is either:
- Another open LLM fine-tuned to mimic the closed model&apos;s outputs
- A smaller model trained to produce similar logits
- A synthesized model built from observed input-output pairs

The proxy costs orders of magnitude less to run than the proprietary model.

### 2. Distilling from the Proxy
Use standard distillation: generate synthetic data from the proxy, train a student model to match the proxy&apos;s outputs and reasoning patterns.

### 3. Optional: Refinement from the Real Teacher
If budget allows, do a final refinement pass on a small high-value dataset using the actual proprietary model. This polishes the student without the full cost.

## Why This Matters for Architects

### Cost Control
- Proprietary models: $0.01–0.10 per 1K tokens (varies). At 1B tokens/day, that&apos;s **$10K–100K monthly**.
- Distilled student: Deploy open weights (Llama, Mixtral, etc.) on your infrastructure. Marginal inference cost → near-zero per-token.
- **ROI window: 2–6 months of API savings covers the distillation cost.**

### Operational Ownership
- Closed APIs: You&apos;re dependent on the vendor&apos;s uptime, rate limits, pricing changes.
- Distilled student: You own the weights. Deploy anywhere—on-prem, containerized, edge devices, air-gapped.

### Latency &amp; Control
- API models: Network round-trip + vendor queue. Latency is unpredictable.
- Local models: Sub-second inference, deterministic performance, no external dependency.

### Quality Preservation
- The student captures 75–90% of the teacher&apos;s quality on most tasks.
- For many enterprise use cases (document classification, customer support, data extraction), this is more than sufficient.

![Performance Comparison Chart](/blog/knowledge-distillation-black-box-llms/fig-3-performance.png)
*Figure 3: Student model accuracy across proxy model sizes — 75–90% of teacher quality achieved with smaller, cheaper proxies.*

### Empirical Results

**Table 1: Overall Benchmark Performance**

| Dataset | Teacher Accuracy | Proxy-KD Student | Quality Ratio |
|---------|------------------|------------------|---------------|
| MMLU (reasoning) | 88.2% | 81.5% | 92% |
| GSM8K (math) | 92.1% | 78.4% | 85% |
| HumanEval (code) | 84.6% | 74.2% | 88% |
| SQuAD (QA) | 95.3% | 89.7% | 94% |
| Classification tasks | 91.4% | 87.3% | 96% |
| **Average** | **90.3%** | **82.2%** | **91%** |

**Table 2: Ablation Study — Component Impact**

| Component | Effect on Accuracy | Compute Cost | Necessity |
|-----------|-------------------|----------------|-----------|
| Proxy model (any size) | baseline | ~1/10th teacher | Essential |
| Proxy fine-tuning (LoRA) | +2-3% | ~5% overhead | Important |
| Token-level distillation loss | +1-2% | &lt;1% overhead | Helpful |
| Teacher refinement pass (small dataset) | +3-5% | ~10-20% teacher cost | Optional (RoI-dependent) |
| Data augmentation (synthetic) | +1-2% | ~5% overhead | Helpful for domains |

## When to Distill

| Scenario | Distill? | Why |
|----------|----------|-----|
| One-off API calls, low volume | ✗ | Cost doesn&apos;t justify overhead |
| High-volume production workload (1M+ calls/month) | ✓ | API costs become painful; distillation ROI is fast |
| Latency-sensitive application | ✓ | Local inference beats API round-trip |
| Compliance/data-residency requirement | ✓ | Can&apos;t send data to external API; self-hosted is mandatory |
| Cost optimization initiative | ✓ | If you&apos;re already paying proprietary bills, distillation is the lever |
| Prototype/research phase | ✗ | Keep the powerful model; optimize later |

## The Implementation Path

1. **Baseline:** Measure quality on your domain tasks (few-shot eval set, ~100 test cases).
2. **Proxy creation:** Fine-tune an open model (Llama 2, Mistral, etc.) on data/outputs from the proprietary model.
3. **Distillation:** Generate synthetic data from the proxy, train a smaller student model (e.g., 7B parameters vs. 70B).
4. **Evaluation:** Test on your baseline. Aim for 80%+ of teacher quality.
5. **Deployment:** Ship the student model to prod. Monitor drift; refresh every 6–12 months.

## Cost-Benefit Example

**Scenario:** Customer support chatbot, 500K conversations/month.

| Method | Monthly Cost | Ownership | Latency |
|--------|--------------|-----------|---------|
| Proprietary API @ $0.03 per 1K tokens | ~$15K | None | ~300ms |
| Distilled student (open model, on-prem) | ~$500 (infra) | Full | ~50ms |
| **Monthly savings** | **$14.5K** | | **6× faster** |
| **Distillation cost (amortized)** | – | – | Paid back in ~1 month |

## The Catch

Distillation isn&apos;t free:
- **Upfront cost:** Engineering time + compute for proxy creation and student training (~2–8 weeks, $10K–50K in cloud cost).
- **Quality trade-off:** The student won&apos;t match the teacher on frontier reasoning tasks. It works best for structured domains (classification, extraction, summarization).
- **Maintenance:** Refresh the student periodically as the world shifts; re-label if the task distribution changes.

## The Bigger Picture

This is architecture-level thinking: **When you&apos;re locked into proprietary models, distillation is your path to independence.**

As LLM costs become a line-item expense in enterprise budgets, the engineers who know how to compress frontier models into deployable, cost-effective alternatives will own the competitive advantage.

The proprietary vendors want you to think distillation is impossible without their weights. It isn&apos;t. 

The technique is proven. The math is sound. The question is whether you&apos;re willing to invest the engineering effort to reclaim control.

---

## References

**Original Research:**
- Chen et al. (2024). &quot;Knowledge Distillation of Black-Box Large Language Models&quot; ([arXiv:2401.07013](https://arxiv.org/abs/2401.07013))
  - Introduces Proxy-KD: distilling proprietary LLM knowledge via an open-source proxy model
  - Empirical validation across reasoning, classification, and generation tasks

**Related Work:**
- Hinton et al. (2015). &quot;Distilling the Knowledge in a Neural Network&quot; — foundational distillation framework
- Hsieh et al. (2023). &quot;Distilling Step-by-Step! Outperforming Larger Language Models with Less Training Data&quot; — task-specific distillation for reasoning

**Open Model Baselines:**
- Meta&apos;s Llama 2 &amp; Llama 3 — strong open-source baselines for student models
- Mistral 7B — efficient, production-ready alternative

**Enterprise Implementation Resources:**
- vLLM — optimized LLM serving (inference speed &amp; cost)
- Ollama — local LLM deployment &amp; management
- Ray Tune — distributed training for distillation workflows

---

**Next Step:** If you&apos;re running on proprietary LLM APIs at scale, audit your usage logs. If monthly costs exceed $5K, distillation becomes a strategic project, not a nice-to-have.

The clock is ticking. Every month you delay is money left on the table.</content:encoded><category>AI</category><category>architecture</category><category>cost-optimization</category><category>LLMs</category><category>enterprise</category><category>technical</category></item><item><title>I built a 51-agent AI system. Here&apos;s what no tutorial will teach you about multi-agent orchestration.</title><link>https://sagarthakkar.com/blog/51-agent-orchestration/</link><guid isPermaLink="true">https://sagarthakkar.com/blog/51-agent-orchestration/</guid><description>The model was never the hard part. Orchestration, routing, and failure modes are. Here&apos;s the architecture.</description><pubDate>Sat, 20 Jun 2026 00:00:00 GMT</pubDate><content:encoded>I run a personal AI system of 51 agents. Not a demo I spun up for a blog post - a system I operate every day, that has failed in every way a distributed system can fail, and that I&apos;ve had to debug at 11pm like any other production service.

The single most expensive mistake I see teams make is this: they design agent systems like chatbots. Free-form conversation, one model trying to do everything, a prompt that grows until nobody understands it. It demos beautifully. It collapses the moment real traffic and real edge cases arrive.

&gt; Most production AI agent systems fail because people design them like chatbots. Agents need clear routing - orchestrator, leads, specialists - not free-form conversation. The same pattern as any well-run org.

## Agents are an org chart, not a conversation

The mental model that actually scales is the one every functioning company already uses. An orchestrator at the top that owns intent and routing. Leads beneath it that own a domain. Specialists beneath them that do one thing well and hand the result back up. Nobody talks to everybody. Authority and scope are explicit.

This isn&apos;t an aesthetic preference. It&apos;s the same reason you don&apos;t run a 200-person company as one giant group chat. Routing is what keeps the system legible as it grows. The moment any agent can call any other agent, you&apos;ve built a graph with no failure boundaries - and you will not be able to reason about it.

## Failure modes are the actual design

Tutorials assume the model returns what you asked for. Production assumes it won&apos;t. A specialist times out. A tool returns malformed JSON. A lead loops because two sub-agents disagree. The interesting engineering is entirely in how the system behaves when a step fails - retries with backoff, circuit-breakers around flaky tools, a budget on tokens and wall-clock per request, and a clear answer to &quot;what does the orchestrator return when a branch never comes back?&quot;

If you can&apos;t draw the failure path, you don&apos;t have an architecture. You have a prompt that happens to work today.

## You cannot operate what you cannot see

Observability is not optional and it is not a dashboard you add later. Every agent hop, every tool call, every token spent is a span. I trace the full tree of a request the way you&apos;d trace a distributed transaction - because that&apos;s exactly what it is. Without it, a regression is invisible until your bill or your latency tells you, and by then you&apos;re debugging blind.

&gt; The model is a commodity. The architecture around it - routing, failure handling, observability - is the entire job. Swap the model and a good system keeps working. Swap the model on a bad one and you find out how much you were leaning on luck.

## What changed my mind

I used to think better models would absorb the architecture problem - that a smart enough model would route itself. Two years of operating this system convinced me of the opposite. LLMs amplify the cost of bad architecture. The more capable the model, the more confidently it executes a badly-routed plan, and the more brutal the design debt becomes when it breaks.

Start with the org chart. Draw the failure paths. Instrument everything. The model is the last thing to worry about, not the first.</content:encoded><category>AI</category><category>Agents</category><category>Architecture</category><category>Orchestration</category></item><item><title>Why Numbers Are Not Enough: Scalars vs Vectors</title><link>https://sagarthakkar.com/blog/why-numbers-are-not-enough/</link><guid isPermaLink="true">https://sagarthakkar.com/blog/why-numbers-are-not-enough/</guid><description>Most people believe mathematics starts with numbers. That belief works-until it doesn&apos;t.</description><pubDate>Wed, 14 Jan 2026 00:00:00 GMT</pubDate><content:encoded>Most people believe mathematics starts with numbers.

That belief works-until it doesn&apos;t.

Imagine you&apos;re looking at a student&apos;s preparation for an exam. You ask a simple question: *How much did you study?*
The answer comes back: **10 hours**.

That number feels informative. It is precise. It is measurable. It is also incomplete.

Ten hours *doing what*?

Reading passively?
Solving problems?
Watching videos?
Being coached?

The moment you ask that follow-up question, pure numbers stop being sufficient. Something deeper is required.

That is where linear algebra actually begins.

---

## Scalars: Quantities Without Direction

A **scalar** is a single number that represents magnitude-*how much* of something exists.

Time, temperature, total money spent, total hours studied.
All scalars.

Scalars are powerful when direction does not matter. If you are measuring how long something took or how heavy something is, a scalar is exactly what you want.

But scalars collapse information.

When you say &quot;10 hours studied,&quot; you flatten every possible way of studying into one number. The number is accurate, but the description is dishonest.

The world rarely behaves like a scalar system.

---

## When Scalar Thinking Breaks Down

Now consider two students:

* Student A studied **8 hours alone** and **2 hours with a coach**
* Student B studied **2 hours alone** and **8 hours with a coach**

Scalar thinking says they are identical: 10 hours each.

Reality disagrees.

Their effort is distributed differently. Their learning experience is different. Their outcomes are likely different.

The problem is not that the number is wrong.
The problem is that the number is **too simple**.

When multiple influences act at once, scalar thinking hides structure instead of revealing it.

---

## Vectors: Quantities With Direction

To describe the students honestly, we need more than one number.

We need something like this:

[
\begin{bmatrix}
\text{self-study hours} \
\text{coaching hours}
\end{bmatrix}
]

This object is called a **vector**.

But calling it an &quot;ordered list of numbers&quot; misses the point.

A vector represents **magnitude and direction together**.

In this case:

* One direction corresponds to self-study
* Another direction corresponds to coaching
* The vector tells us *how much effort was applied in each direction*

Each student is no longer a number.
Each student is a **state**.

![Image](https://www.grc.nasa.gov/www/k-12/airplane/Images/vectors.jpg)

![Image](https://studywell.com/wp-content/uploads/2021/05/2DVectors.png)

---

## Why Direction Changes Everything

Two vectors can have the same length and still mean very different things.

Student A&apos;s effort points mostly toward self-study.
Student B&apos;s effort points mostly toward coaching.

Same magnitude. Different direction.

Linear algebra treats these as fundamentally different objects, because **direction encodes behavior**.

This is the first major mental shift:

&gt; Numbers tell you *how much*.
&gt; Vectors tell you *how*.

Once you accept this, many real-world problems suddenly become representable instead of awkward.

---

## From Values to States

A scalar answers:

&gt; &quot;How big is it?&quot;

A vector answers:

&gt; &quot;Where is it in relation to everything else?&quot;

That difference is subtle but profound.

In data science, machine learning, economics, physics, and engineering, we rarely care about isolated quantities. We care about **configurations**.

A user is not &quot;30 years old.&quot;
A user is a point in a space of age, income, behavior, preferences, and history.

A system is not &quot;under load.&quot;
A system is operating across CPU, memory, network, and latency dimensions simultaneously.

These are not scalar problems. They never were.

---

## Why Linear Algebra Starts Here

Linear algebra is often introduced with symbols, rules, and matrices. That ordering is backwards.

The real starting point is this realization:

&gt; Many phenomena cannot be described honestly with a single number.

Vectors exist because reality has direction.

Once you begin modeling systems as vectors instead of scalars, everything else-dot products, matrices, projections-becomes a natural extension instead of an abstraction.

---

## The Takeaway

Scalars are not wrong.
They are incomplete.

Vectors do not complicate reality.
They **respect it**.

If you are still thinking in scalars, linear algebra will feel artificial.
Once you start thinking in vectors, it will feel inevitable.</content:encoded><category>linear-algebra</category><category>maths</category><category>vectors</category></item><item><title>Token-Based vs Session-Based Security: An Architect&apos;s Perspective</title><link>https://sagarthakkar.com/blog/token-vs-session-security/</link><guid isPermaLink="true">https://sagarthakkar.com/blog/token-vs-session-security/</guid><description>A practical breakdown of session vs token security, when to use which, and modern best practices.</description><pubDate>Sat, 13 Dec 2025 00:00:00 GMT</pubDate><content:encoded>![Token VS Session Overview](/attachments/token-vs-session-overview.png)

Below is the simplest, most practical breakdown of **Token-Based** vs **Session-Based** security.

## ✅ Session-Based Security (Traditional Web Login)

### How Session-Based Security Works

1. **User logs in**.
2. **Server creates a session object** and keeps it in memory, DB, or cache (e.g., Redis).
3. **A session ID is stored in a browser cookie**.
4. **Client** sends the cookie with every request.

![Session Based Auth Flow](/attachments/session-based-auth-flow.png)

### Session-Based Characteristics

- **Server maintains state**.
- Sessions expire or logout triggers invalidation.
- Good for classic web apps (monoliths, server-rendered).

### Session-Based Pros

- **Simple to implement**.
- **Easy to revoke sessions**.
- Well supported by frameworks.

### Session-Based Cons

- **Doesn’t scale easily** across multiple servers (needs sticky sessions or shared store like Redis).
- **Mobile apps &amp; APIs don’t fit well** (cookies are tricky on mobile).
- Requires server memory/storage for each user session.

---

## ✅ Token-Based Security (Modern APIs &amp; Mobile/Web)

### How Token-Based Security Works

1. **User logs in**.
2. **Server generates a token** (JWT, opaque token, PASETO) and signs it.
3. **Token is sent to client** and included in every request (usually in `Authorization` header).
4. **Server does not store session state** - it validates the signature to trust the token.

![Token Based Auth Flow](/attachments/token-based-auth-flow.png)

### Token-Based Characteristics

- **Stateless**.
- Scales horizontally easily.
- Works across mobile, web, APIs, and microservices.

### Token-Based Pros

- **Perfect for distributed systems**.
- **No session storage required** on server.
- Easy to integrate with third parties.
- Works across domains (CORS friendly).

### Token-Based Cons

- **Harder to revoke** (token is valid until expiry unless you maintain a blacklist/allowlist).
- **Larger attack surface** if token is stolen (especially if stored in `localStorage`).

---

## 🆚 Simple Comparison in One Line

![Security Comparison Matrix](/attachments/security-comparison-matrix.png)

| Feature | Session-Based | Token-Based |
| :--- | :--- | :--- |
| **Server stores session?** | Yes | No |
| **Scales easily?** | No | Yes |
| **Best for** | Web apps | APIs, mobile, microservices |
| **Revocation** | Easy | Harder |
| **Implementation** | Simple | Requires careful design |

---

## 🧠 Architect-Level Guidance - What Else You MUST Know in 2025

### 1️⃣ JWT is NOT always the right choice

People overuse JWTs. Use JWTs when:

- You need cross-service trust.
- You have distributed microservices.
- You avoid session storage by design.

**Avoid JWTs when:**

- You need quick revocation options.
- You don’t trust clients fully.
- Sessions are short-lived and centralized.

### 2️⃣ PASETO is the modern, safer alternative to JWT

- JWT has known pitfalls (alg confusion, signature issues).
- **PASETO** (Platform-Agnostic Security Tokens) fixes those by design.

### 3️⃣ OAuth2 / OpenID Connect ≠ Token-Based Auth

These are protocols, not just &quot;authentication methods&quot;. They use tokens, but solve:

- Authorization delegation.
- Identity federation.
- SSO (Single Sign-On).

### 4️⃣ Zero-Trust Security Models Prefer Tokens

In microservices, you need:

- Mutual TLS (mTLS).
- Service-to-service tokens.
- No server-stored sessions.

### 5️⃣ For Internal Enterprise Apps → Hybrid Approach

- Use **Session cookies for browser UX**.
- Use **Token exchange for APIs**.
Both can co-exist and are common in modern systems.

### 6️⃣ For Mobile Apps → ALWAYS Token-Based

- Sessions break easily on mobile networks.
- Tokens are the standard for resilience.</content:encoded><category>Security</category><category>Architecture</category><category>Auth</category></item><item><title>The Insight That Unlocks Linear Algebra for Engineers</title><link>https://sagarthakkar.com/blog/linear-algebra-insight-for-engineers/</link><guid isPermaLink="true">https://sagarthakkar.com/blog/linear-algebra-insight-for-engineers/</guid><description>Discover why matrices are not just tables of numbers, but functions in disguise. A paradigm shift that transforms how engineers think about systems, transformations, and architecture.</description><pubDate>Tue, 10 Dec 2024 00:00:00 GMT</pubDate><content:encoded>Most of us were taught matrices as **tables of numbers**. Rows. Columns. Formulas. Memorize and move on. And that&apos;s exactly why so many engineers quietly develop a fear of linear algebra.

But here&apos;s the insight that recently clicked for me - and I&apos;m still processing it layer by layer:

**A matrix is not data. It&apos;s a function-disguised as data.**

I&apos;m still comprehending this idea more deeply, but even at this stage, it has completely shifted how I look at systems, architecture, and transformations. And I&apos;ll keep sharing more as I understand it better.

## Why This Matters to Engineers and Architects

When you multiply a matrix by a vector, you&apos;re not calculating-you&apos;re **transforming**.

- **Stretch** dimensions
- **Rotate** coordinate systems
- **Project** into different spaces
- **Compress** information
- **Shift** perspectives
- **Re-orient** reference frames
- **Change** viewpoints

This isn&apos;t math trivia-this is exactly how:

- Neural networks transform data through layers
- Graphics engines move 3D objects in real-time
- Robotics systems adjust direction and orientation
- Simulations evolve states over time
- Embeddings encode semantic meaning

Matrices are everywhere around us-quietly doing the work of functions.

## So Why Do They Look Like Tables?

Because storing the actual transformation like &quot;Rotate 30° and stretch the Y-axis by 3x&quot; would be messy to write and unstructured for computers.

So mathematics found a clean solution:

**Store how the function acts on basis vectors.**

That grid of numbers isn&apos;t recording data-it&apos;s recording the *behavior* of a transformation. Each column tells you where a basis vector lands after the transformation is applied.

## A Matrix is a Controller, Not a Container

Think of a video game controller:

🎮 The controller is not the movement-it&apos;s the *device that causes movement.*

Similarly:

- **Matrix** → the controller
- **Vector** → the character&apos;s position
- **Multiplication** → pressing buttons
- **Output** → new position

Once you see matrices as actions-not numbers-the whole subject becomes intuitive. (At least it&apos;s starting to for me, and I&apos;ll keep you posted as I go deeper.)

## Why This Matters for Engineering Leadership

As architects and tech leaders, we constantly deal with:

- High-dimensional problems
- State changes and transitions
- Transformations of data
- Modelling system behavior
- Abstraction design
- Complex system interactions

Understanding the &quot;matrix = function&quot; mental model strengthens how we think about **systems, change, operations, and behavior**.

Linear algebra becomes more than a subject-it becomes a **thinking framework** for understanding how systems transform and evolve.

## Key Takeaway

&gt; **A matrix is a linear transformation stored in a data-friendly format.**

I&apos;m still refining my mental model, but this insight alone unlocked 50% of the subject for me. If you&apos;re an engineer who&apos;s struggled with linear algebra, try shifting your perspective: stop seeing matrices as static tables and start seeing them as dynamic transformations.

The moment you make that shift, everything from machine learning to computer graphics to system design starts making a lot more sense.

---

*What insights have transformed your understanding of technical concepts? I&apos;d love to hear your &quot;aha&quot; moments in the comments.*</content:encoded><category>Linear Algebra</category><category>Engineering</category><category>Architecture</category><category>Learning</category></item></channel></rss>