পাঠ্যক্রম খুলুন
অগ্রসর পর্যায়

URL Shortener: পূর্ণ মক ইন্টারভিউ

Mock Interview: URL Shortener

এই পাঠের কুইজ ↓৭ মিনিট পড়াPHP 8.3+ · Laravel 12
এই পাঠের সূচিপত্র

এই পাঠে যা শিখবেন

  • সম্পূর্ণ sample response থেকে reasoning flow দেখা
  • Hot redirect ও revocation deep dive করা
  • Failure followup-এর concrete উত্তর অনুশীলন

সমস্যা দিয়ে শুরু

Interviewer: URL shortener design করুন। Candidate: public redirect এবং authenticated creation ধরছি; owner link disable করতে পারবেন কি? উত্তর: হ্যাঁ, custom alias optional। Candidate: analytics approximate হলে চলবে? উত্তর: হ্যাঁ, redirect বন্ধ করা যাবে না। এখানে sample conversation original practice scenario। Numbers assumptions, কোনো real company traffic নয়। Primary objective fast available redirect, তার সঙ্গে bounded disable propagation। Private document-sharing link এই scope নয়; হলে authorization বদলাবে।

সহজ করে বুঝি

Candidate response: POST /links validated http/https destination নেবে, 201-এ code ও short URL দেবে। GET /{code} mapping দেখে 302 দেবে। DELETE /links/{id} owner policy দিয়ে disable করবে। links table-এ internal id, unique code, destination,owner_id,expires_at,disabled_at,version রাখব। Code random namespace থেকে আসে, unique constraint collision-এর final guard; conflict হলে bounded regeneration। Same create operation retry duplicate link তৈরি করতে পারবে কি না requirement অনুযায়ী operation key যোগ করব।

পরিচিত একটি উপমা

এটি library reference desk: short code call number, database মূল catalog এবং cache desk-এর quick lookup card। জনপ্রিয় বইয়ের card কাছে রাখা দ্রুত; catalog-এ নিষিদ্ধ entry হলে desk-এর card-ও update করতে হয়।

নকশাটি দেখুন

Diagram লোড হচ্ছে…

পূর্ণ mock-এ design হলো justified chain: scope → assumptions → mapping contract → hot read path → revocation/failure boundary।
Diagram-এর text flow দেখুন
flowchart TD
 C[Create with validation and quota] --> D[(Authoritative mapping)]
 R[Public redirect] --> E[Edge or local cache]
 E --> K[Shared cache]
 K -->|Miss| D
 K --> X[302 destination]
 X --> Q[Bounded analytics queue]
 O[Disable owner action] --> D
 O --> I[Invalidate versioned caches]

Candidate: diagram-এ write source relational store। Redirect first hot cache, তারপর shared cache, miss-এ source। Analytics enqueue best-effort হবে বলে queue unavailable-এ redirect চলবে; loss metrics দেব। Disable path version বদলিয়ে invalidation করে। Interviewer: cache failure? Candidate: uncapped database fallback দেব না; coalesced miss, bounded concurrency ও stale policy দেখব। Disabled/security-sensitive entry stale serve করা acceptable কি না agreed propagation bound অনুযায়ী হবে।

PHP ও Laravel-এ প্রয়োগ

Candidate estimate: দিনে ১০ লাখ create ও ১০ কোটি redirect ধরলে average প্রায় ১২ write এবং ১১৫৭ redirect QPS। দশগুণ peak কেবল assumption, load test-এ যাচাই করব। এক বছর create record ৩৬.৫ কোটি; record ৫০০ byte ধরলে raw প্রায় ১৮২.৫GB, index/replica/backup অতিরিক্ত। Laravel redirect controller fragment নিচে। Cache ৩০ seconds TTL illustrative; model expires_at datetime cast। URL validation এবং owner disable endpoint আলাদা, code route bounded।

php
use App\Models\ShortLink;
use Illuminate\Support\Facades\Cache;
$mapping = Cache::remember("link:{$code}", 30, function () use ($code) {
    return ShortLink::query()->where('code', $code)->first();
});
abort_if($mapping === null || $mapping->disabled_at !== null, 404);
abort_if($mapping->expires_at?->isPast(), 410);
return redirect()->away($mapping->destination, 302);

সুবিধা, সীমাবদ্ধতা ও trade-off

Interviewer: কেন 301 নয়? Candidate: destination change এবং disable-এর পরে long-lived client cache নিয়ন্ত্রণ গুরুত্বপূর্ণ, তাই temporary redirect দিয়ে explicit caching policy শুরু করব। Immutable permanent link requirement হলে 301 বিবেচনা করব। কেন SQL? Mapping uniqueness ও owner operation সহজ, measured capacity ছাড়া sharding লাগাচ্ছি না। Read replica stale হতে পারে; disable freshness critical path কোথায় authoritative check দরকার তা আলাদা করব।

সাধারণ ভুল

  • Sample QPS-কে universal traffic benchmark হিসেবে মুখস্থ করা।
  • Random code-কে private authorization token হিসেবে promise করা।
  • Cache outage-এ unlimited source read খুলে দেওয়া।

আরও একটু গভীরে

Candidate deep dive: celebrity link একটি shard hot করতে পারে। Consistent hashing total load balance করলেও single hot key ভাগ করে না। Edge/local cache এবং request coalescing সেই key-এর source load কমাবে। Cache stampede test করব। Abuse দিক থেকে create quota, takedown workflow ও destination safety checks চাই; server দিয়ে arbitrary destination fetch করলে SSRF risk আলাদা। Analytics-এ IP data minimization এবং retention policy রাখব। Observability-তে redirect success ratio, p95/p99, cache miss, source saturation ও disable lag মাপব। Recovery-তে mapping backup restore rehearsal দরকার; analytics loss acceptable হলেও mapping loss নয়। শেষে limitation বলব: globally instant revocation ও private access এই simple architecture guarantee করে না।

মনে রাখুন

পূর্ণ mock-এ design হলো justified chain: scope → assumptions → mapping contract → hot read path → revocation/failure boundary।

নিজে চেষ্টা করুন

এই answer না দেখে প্রথমে নিজের ৪৫ মিনিট mock করুন। তারপর requirement বদলান: private short links এবং zero-tolerance revoke। কোন cache layer আর public redirect চলবে না লিখুন। Estimate arithmetic, single-hot-key scenario এবং database outage response aloud explain করুন।

নিজের বোঝা যাচাই করুন

1. এই diagram একমাত্র সঠিক?

না। Stated requirements-এর একটি defensible starting design। Different workload বা revocation bound alternative justify করতে পারে।

2. Single hot key sharding solve করে?

সাধারণ key partition এক key একই owner-এ রাখে। Hot-key caching/replication ও request coalescing আলাদা দরকার।

3. Create key collision কোথায় ধরা?

Database unique constraint-এ। Application random generator collision probability কমায়, final correctness constraint রাখে।

4. Analytics loss acceptable কেন?

এই mock-এ explicit scope। Billing analytics হলে durability requirement বদলাবে, তাই sample policy blindly reuse নয়।

5. শেষ recap কী হবে?

Mapping durable, redirect cache-driven, owner disable bounded freshness, analytics async এবং source overload controlled—এই promises ও limitation বলুন।

আরও পড়ুন

এই পাঠের কুইজ

এই পাঠ থেকে ২টি প্রশ্ন। উত্তর দিয়ে ব্যাখ্যা দেখুন; অধ্যায়ের কুইজ আলাদাভাবে দিতে হবে।

এই পাঠের ২টি প্রশ্নের উত্তর দিন। পাস করতে দুটিই সঠিক হতে হবে।

জমা দেওয়ার পর সঠিক উত্তর ও ব্যাখ্যা দেখবেন। ফলাফল এই ব্রাউজারে সংরক্ষিত থাকবে। অনুশীলনের ফল অধ্যায় সম্পন্নের হিসাবে যোগ হয় না।

সব বিষয় মিলিয়ে অনুশীলন করুন →

অগ্রগতি এই ব্রাউজারে সংরক্ষিত থাকে। শুধু পাঠ খুললে সম্পন্ন হয় না।