<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Engineering on Vijay Pagare</title><link>/blog/engineering/</link><description>Recent content in Engineering on Vijay Pagare</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Sun, 12 Apr 2026 00:21:44 +0530</lastBuildDate><atom:link href="/blog/engineering/index.xml" rel="self" type="application/rss+xml"/><item><title>The Pattern Behind Kadane's Algorithm</title><link>/kadanes-algorithm-pattern/</link><pubDate>Sun, 12 Apr 2026 00:04:00 +0530</pubDate><guid>/kadanes-algorithm-pattern/</guid><description>&lt;p>Kadane’s Algorithm is a classic dynamic programming technique used to find the Maximum Subarray Sum within a one-dimensional array of numbers. It’s famous for its efficiency, turning what could be a brute-force $O(N^2)$ problem into a sleek $O(N)$ linear scan.&lt;/p>
&lt;hr>
&lt;h2 id="1-what-is-kadanes-algorithm">1. What is Kadane’s Algorithm?&lt;/h2>
&lt;p>The algorithm iterates through an array, keeping track of the maximum sum ending at the current position. It makes a simple choice at every element:&lt;/p></description></item><item><title>Design: Activity Feed</title><link>/diary/design-activity-feed/</link><pubDate>Wed, 08 Apr 2026 20:40:39 +0530</pubDate><guid>/diary/design-activity-feed/</guid><description>&lt;h3 id="the-problem">The Problem&lt;/h3>
&lt;p>In an activity feed (like LinkedIn or Instagram), we need to track which posts a user has already seen.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>The Scale:&lt;/strong> Millions of active users.&lt;/li>
&lt;li>&lt;strong>The Volume:&lt;/strong> Every scroll generates a &amp;ldquo;Seen&amp;rdquo; event. This is a massive write-heavy workload.&lt;/li>
&lt;li>&lt;strong>The Goal:&lt;/strong> Ensure we don&amp;rsquo;t show the same post twice to the same user upon refresh.&lt;/li>
&lt;/ul>
&lt;h3 id="1-the-storage-strategy-the-write-path">1. The Storage Strategy (The Write Path)&lt;/h3>
&lt;p>If we use a traditional SQL database, every &amp;ldquo;seen&amp;rdquo; event requires the DB to find a specific row and update it. This involves &amp;ldquo;Random I/O,&amp;rdquo; which is slow. At 100k+ events per second, a standard relational database will struggle with locking and disk contention.&lt;/p></description></item><item><title>Overview: System Design</title><link>/overview-system-design/</link><pubDate>Wed, 08 Apr 2026 20:32:43 +0530</pubDate><guid>/overview-system-design/</guid><description>&lt;p>Shoutout – &lt;a href="https://paperdraw.dev" 
 target="_blank" rel="noopener" >https://paperdraw.dev&lt;/a> (System Design w/ simulations)&lt;/p>
&lt;p>System Design ain&amp;rsquo;t about developing features or writing code, it&amp;rsquo;s about managing trade-offs between speed, reliability, and cost. Below is the &amp;ldquo;index&amp;rdquo; of topics required to navigate top-tier architecture discussions.&lt;/p>
&lt;h2 id="1-the-storage-layer-beyond-crud">1. The Storage Layer: Beyond CRUD&lt;/h2>
&lt;p>Understanding how data is physically stored determines how your system scales.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>B-Trees vs. LSM-Trees:&lt;/strong> The fundamental trade-off between Read-optimization (SQL) and Write-optimization (NoSQL).&lt;/li>
&lt;li>&lt;strong>Storage Paradigms:&lt;/strong> When to use Relational (ACID compliance), Document (flexible schema), Key-Value (low latency), or Graph (complex relationships).&lt;/li>
&lt;/ul>
&lt;h2 id="2-distributed-communication">2. Distributed Communication&lt;/h2>
&lt;p>How services talk to each other defines the user experience and system resilience.&lt;/p></description></item><item><title>Design: URL Shortener</title><link>/diary/design-url-shortener/</link><pubDate>Mon, 06 Apr 2026 16:27:00 +0530</pubDate><guid>/diary/design-url-shortener/</guid><description>&lt;p>Started learning system design and architecture seriously. I&amp;rsquo;ll be posting daily notes on whatever i learn about the subject going forward. Here&amp;rsquo;s the first one–enjoy!&lt;/p>
&lt;h3 id="1-the-core-base62-encoding">1. The Core: Base62 Encoding&lt;/h3>
&lt;p>To keep URLs short, we use &lt;strong>Base62 encoding&lt;/strong> (&lt;code>[a-z, A-Z, 0-9]&lt;/code>).&lt;/p>
&lt;ul>
&lt;li>A 7-character string gives us &lt;strong>3.5 Trillion combinations&lt;/strong>.&lt;/li>
&lt;li>&lt;strong>Why not Base64?&lt;/strong> Base64 includes &lt;code>+&lt;/code> and &lt;code>/&lt;/code>, which are not URL-safe and can break paths.&lt;/li>
&lt;/ul>
&lt;h3 id="2-the-coordination-problem-key-generation-service-kgs">2. The Coordination Problem: Key Generation Service (KGS)&lt;/h3>
&lt;p>In a distributed system, we must prevent &amp;ldquo;collisions&amp;rdquo; where two servers generate the same ID.&lt;/p></description></item><item><title>Academic AI Fundamentals</title><link>/academic-ai-fundamentals/</link><pubDate>Tue, 16 Sep 2025 01:45:39 +0530</pubDate><guid>/academic-ai-fundamentals/</guid><description>&lt;p>Lord Rama, was doing BFS search until he met Jatayu, then he started DFS.&lt;/p>
 &lt;img src="../../images/rama-dfs-bfs.png" alt="Lord Rama and BFS, DFS analogy" />


&lt;div class="callout-container">
 &lt;div class="callout-emoji">&lt;/div>
 &lt;div class="callout-content">Note - This document was created on &lt;a href="https://www.notion.so/pagarevijayy/Notes-AI-Fundamentals-26f41fc193de80f0b2bddc69f32573a1?source=copy_link" 
 target="_blank" rel="noopener" >notion&lt;/a>. It looks more readable there.&lt;/div>
&lt;/div>
&lt;h2 id="search-methods-for-problem-solving">Search Methods for Problem Solving.&lt;/h2>
&lt;h4 id="state-space-search">State space search&lt;/h4>
&lt;ul>
&lt;li>should be precise&lt;/li>
&lt;li>be able to analyse&lt;/li>
&lt;li>&lt;code>S = { S, A, Action(s), Result(s,a), Cost(s,a) }&lt;/code>&lt;/li>
&lt;/ul>
&lt;h4 id="search-types-uninformed-blind-brute-force-and-informed-heuristic">Search Types: Uninformed (blind, brute force) and Informed (heuristic)&lt;/h4>
&lt;table>
 &lt;tr>
 &lt;td>&lt;b>Uninformed&lt;/b>&lt;/td>
 &lt;td>&lt;b>Informed&lt;/b>&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>search without information&lt;/td>
 &lt;td>search with information&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>no knowledge&lt;/td>
 &lt;td>use knowledge to find steps to solution&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>time consuming&lt;/td>
 &lt;td>quicker solution&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>more complexity (time, space)&lt;/td>
 &lt;td>less complexity (time, space)&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>DFS, BFS&lt;/td>
 &lt;td>A*, Heuristic DFS, Best first search&lt;/td>
 &lt;/tr>
&lt;/table>
&lt;h4 id="bfs---uninformed---breadth-first-search">BFS - uninformed - breadth first search&lt;/h4>
&lt;ul>
&lt;li>uninformed search technique&lt;/li>
&lt;li>FIFO (queue)&lt;/li>
&lt;li>Shallowest node&lt;/li>
&lt;li>complete (means it will provide the answer)&lt;/li>
&lt;li>optimal (shortest result/cost)&lt;/li>
&lt;li>time complexity = O(V + E) in Data Structures; in &lt;code>AI → O(b^d)&lt;/code> where b: branch factor and d: depth (of tree)&lt;/li>
&lt;li>example: tree&lt;/li>
&lt;/ul>
&lt;h4 id="dfs---uninformed---depth-first-search">DFS - uninformed - depth first search&lt;/h4>
&lt;ul>
&lt;li>uninformed search technique&lt;/li>
&lt;li>stack (LIFO)&lt;/li>
&lt;li>deepest node&lt;/li>
&lt;li>incomplete (possible that dfs doesn’t give a solution gets stuck in a loop or infinite search space)&lt;/li>
&lt;li>non-optimal ()&lt;/li>
&lt;li>time complexity = O(V+E); in &lt;code>AI → O (b^d)&lt;/code>; b: branching factor, d: depth&lt;/li>
&lt;li>space complexity = O(b*d)&lt;/li>
&lt;li>example: &lt;a href="https://www.youtube.com/watch?v=f8luGFRtshY&amp;amp;list=PLAXUYU7PbJhhg1jaU2gasFmh4FlMXvq-P&amp;amp;index=4" 
 target="_blank" rel="noopener" >tree&lt;/a>&lt;/li>
&lt;/ul>
&lt;h4 id="dfs-family---depth-bounded-iterative-deepening">DFS family - Depth Bounded, Iterative Deepening&lt;/h4>
&lt;table>
 &lt;tbody>
 &lt;tr>
 &lt;td>&lt;b>Depth-Limited Search (DLS)&lt;/b>&lt;/td>
 &lt;td>&lt;b>Iterative Deepening Depth-First Search (IDDFS)&lt;/b>&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>Depth is fixed — search is restricted to a certain depth so that it doesn’t encounter a loop or go into infinitely deep space.&lt;/td>
 &lt;td>Iteratively first checks for depth 1, then 2, then 3, and so on... till the goal is found.&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>&lt;b>Completeness:&lt;/b> NO (if the solution is beyond the depth limit)&lt;/td>
 &lt;td>&lt;b>Completeness:&lt;/b> YES (if the branching factor 'b' is finite)&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>&lt;b>Optimality:&lt;/b> NO (it might find a non-optimal solution if a solution exists at a shallower depth but is not explored due to the limit)&lt;/td>
 &lt;td>&lt;b>Optimality:&lt;/b> YES (it is guaranteed to find the shallowest goal)&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>&lt;b>Time Complexity:&lt;/b> $O(b^l)$ where 'l' is the depth limit.&lt;/td>
 &lt;td>&lt;b>Time Complexity:&lt;/b> $O(b^d)$ where 'd' is the depth of the shallowest solution. (This is asymptotically equivalent to BFS and DFS for large d)&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>&lt;b>Space Complexity:&lt;/b> $O(bl)$ where 'l' is the depth limit. (Same as DFS)&lt;/td>
 &lt;td>&lt;b>Space Complexity:&lt;/b> $O(bd)$ where 'd' is the depth of the shallowest solution. (Same as DFS)&lt;/td>
 &lt;/tr>
 &lt;/tbody>
&lt;/table>
&lt;h4 id="bidirectional-search-extension-of-bfs-dfs">Bidirectional search (extension of BFS, DFS)&lt;/h4>
&lt;ul>
&lt;li>Two simultaneous searches - from initial to goal &amp;amp; from goal to initial, stops when two meets.&lt;/li>
&lt;li>time &lt;a href="https://www.youtube.com/watch?v=rEema9uQ02c&amp;amp;list=PLAXUYU7PbJhhg1jaU2gasFmh4FlMXvq-P&amp;amp;index=6" 
 target="_blank" rel="noopener" >complexity&lt;/a> = O(2* b^d/2)&lt;/li>
&lt;li>complete in BFS, not complete in DFS&lt;/li>
&lt;/ul>
&lt;h4 id="heuristics---informed-search">Heuristics - Informed search&lt;/h4>
&lt;ul>
&lt;li>Used to solve a problem quickly&lt;/li>
&lt;li>For solving non-polynomial problem (i.e. the ones having exponential complexity) in polynomial times.&lt;/li>
&lt;li>a good enough solution will be reached (may not be the optimal)&lt;/li>
&lt;li>&lt;a href="https://www.youtube.com/watch?v=5F9YzkpnaRw&amp;amp;list=PLAXUYU7PbJhhg1jaU2gasFmh4FlMXvq-P&amp;amp;index=7" 
 target="_blank" rel="noopener" >Technique&lt;/a>:
&lt;ul>
&lt;li>eucledian distance&lt;/li>
&lt;li>manhatten distance or no. of misplaced tiles (8 puzzle problem - complexity O(3^20))&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h4 id="greedy-best-first-search">Greedy best first search&lt;/h4>
&lt;ul>
&lt;li>Combines BFS and DFS to form best first search&lt;/li>
&lt;li>use of heuristic&lt;/li>
&lt;li>admissibility: h(n) ≤ h*(n) i.e. h(n) should always be less than or equal to actual cost. (heuristic function should not over estimate.)&lt;/li>
&lt;li>if f(n) = h(n) → optimal solution. (i.e. actual cost = heuristic function); sometimes the solution can be optimal even if actual cost is greater. [&lt;a href="https://www.youtube.com/watch?v=O9Bp5O2aeu0&amp;amp;list=PLAXUYU7PbJhhg1jaU2gasFmh4FlMXvq-P&amp;amp;index=8" 
 target="_blank" rel="noopener" >but actual cost cant be less&lt;/a>]&lt;/li>
&lt;li>completeness - NO, optimality - NO&lt;/li>
&lt;li>time and space complexity = O(b^m)&lt;/li>
&lt;/ul>
&lt;h4 id="a---informed-search">A* - informed search&lt;/h4>
&lt;ul>
&lt;li>&lt;code>f(n) = g(n) + h(n)&lt;/code> where g(n) is actual cost from start node to n; h(n) is estimation cost from n to goal node.&lt;/li>
&lt;li>Example - &lt;a href="https://www.youtube.com/watch?v=tvAh0JZF2YE&amp;amp;list=PLAXUYU7PbJhhg1jaU2gasFmh4FlMXvq-P&amp;amp;index=10" 
 target="_blank" rel="noopener" >directed graph&lt;/a>&lt;/li>
&lt;li>optimal&lt;/li>
&lt;li>time and space complexity = O(b^d)&lt;/li>
&lt;/ul>
&lt;h4 id="a-admissibility---underestimate-overestimate">A* admissibility - underestimate, overestimate&lt;/h4>
&lt;ul>
&lt;li>h(n) ≤ h*(n) → &lt;strong>underestimation [ optimal solution ]&lt;/strong>
&lt;ul>
&lt;li>h(n) is heuristic value and h*(n) is the actual/optimal value&lt;/li>
&lt;li>we always get optimal solution in case of &lt;em>underestimation&lt;/em>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>h(n) ≥ h*(n) → &lt;strong>overestimation&lt;/strong> (may not be the optimal)&lt;/li>
&lt;li>&lt;a href="https://www.youtube.com/watch?v=xz1Nq6cZejI&amp;amp;list=PLxCzCOWd7aiHGhOHV-nwb0HR5US5GFKFI&amp;amp;index=21" 
 target="_blank" rel="noopener" >example&lt;/a>&lt;/li>
&lt;/ul>
&lt;h4 id="hill-climbing---local-search-algorithm">Hill climbing - Local search algorithm&lt;/h4>
&lt;ul>
&lt;li>Local search algorithm, &lt;a href="https://www.youtube.com/watch?v=3SiWtAnUROs&amp;amp;list=PLAXUYU7PbJhhg1jaU2gasFmh4FlMXvq-P&amp;amp;index=9" 
 target="_blank" rel="noopener" >no backtracking&lt;/a>&lt;/li>
&lt;li>Algorithm:
&lt;ol>
&lt;li>Evaluate initial state&lt;/li>
&lt;li>Loop until a solution is found or there are no operators left
&lt;ol>
&lt;li>select and apply a new operator&lt;/li>
&lt;li>evaluate the new state&lt;/li>
&lt;li>if goal then quit&lt;/li>
&lt;li>if better than current state then it is new current state&lt;/li>
&lt;/ol>
&lt;/li>
&lt;/ol>
&lt;/li>
&lt;li>Problems: local maxima, plateau/flat maxima, ridge&lt;/li>
&lt;li>Good for a few problems.&lt;/li>
&lt;li>Better space complexity&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>tbd:&lt;/strong>&lt;/p></description></item></channel></rss>