Skip navigation
Answer 👇 Most developers immediately say: “Use a Stack.” And they’re partially correct.
0:00

Answer 👇 Most developers immediately say: “Use a Stack.” And they’re partially correct.

Answer 👇 Most developers immediately say: “Use a Stack.” And they’re partially correct. But production browsers do much more than that. ━━━━━━━━━━━━━━━━━━━━ 📌 The Real Problem Imagine you accidentally close: • Tab A • Tab B • Tab C Now you click “Reopen Closed Tab.” Which tab comes back first? ✅ Tab C — the most recently closed tab. Why? Because Chrome follows the Last In, First Out (LIFO) principle, which is exactly how a Stack works. ━━━━━━━━━━━━━━━━━━━━ 📌 Step 1 – Push on Close Every time you close a tab, Chrome stores: • URL • Title • Session State • Scroll Position ...and pushes this information onto a stack. Example: Close A Close B Close C Stack: Top → C B A ━━━━━━━━━━━━━━━━━━━━ 📌 Step 2 – Pop on Restore When you press “Reopen Closed Tab”: Chrome pops the top element from the stack. Result: ✅ First restore → C ✅ Second restore → B ✅ Third restore → A This is a perfect example of LIFO (Last In, First Out). ━━━━━━━━━━━━━━━━━━━━ 📌 Step 3 – What Happens in Production? A simple in-memory stack isn’t enough. If Chrome crashes or your computer restarts, users still expect their tabs to come back. That’s why browsers periodically persist session metadata to disk. This enables: ✔ Crash Recovery ✔ Session Restoration ━━━━━━━━━━━━━━━━━━━━ 💡 Real Production Design • Stack → Stores recently closed tabs • Memory → Provides instant restoration • Disk Storage → Stores session backup for crash recovery ━━━━━━━━━━━━━━━━━━━━ 🎯 Interview Ready Answer “Chrome’s Reopen Closed Tab feature is primarily implemented using a Stack because it follows the LIFO (Last In, First Out) principle. In production systems, browsers enhance this by persisting session metadata to disk, allowing crash recovery and complete session restoration.” Follow @aneeshaparti for more Java, System Design & Backend Engineeri

Comments

Comments from the original post on Instagram

No comments yet