Microsoft system design questions: what candidates report and how to answer
The design prompts candidates report for Microsoft, a worked Teams-style chat design with ordering and fan-out, a tested C# cache with a swappable eviction policy, and the senior follow-ups.
GuideAppliedMicrosoft guide18 min readUpdated
- 1 architecture diagram
- 1 sequence flow
- 2 data models
- 2 API designs
- 4 code samples
- 6 interviewer follow-ups
- 3 self-checks
On this page9 sectionsHLDLLDSenior depth
Read first: A framework for system design interviews
- Separate what Microsoft publishes about its design round from the prompts candidates report, and use the reported prompts as themes, not a question bank.
- Design a Teams-style chat service end to end: connections, ordering, delivery, fan-out and storage.
- Write a thread-safe in-memory cache in C# with a swappable eviction policy, and say what comes after one lock.
- Answer the senior follow-ups on huge channels, offline devices and failover.
4 code samples (189 lines), collapsed so the explanation stays in focus.
Design prompts are easier to practise than to predict. Nobody outside Microsoft can tell you which one you will get, but the same few building blocks sit under all of them: real-time connections, ordering, queues, caches, storage and failure. This guide lists what candidates say they were asked, then works two of the prompts in full.
What Microsoft says about the design round is in the first guide: a short interview of about 45 minutes, a syllabus that names distributed systems, resiliency, availability, replication, CAP and partitioning, and advice to clarify, plan, think aloud and check your work. What candidates add is anecdote, and it varies by team, level and year.
| What you read | Who said it | How to use it |
|---|---|---|
| A four-round onsite of 45-minute interviews. The first mixed system design with object-oriented design, and the second was a standard design question with heavy follow-ups | One candidate, from a 2022 hiring event | Prepare for a design round that has a class-design half. The cache library below is that half. |
| The expectation was a high-level design plus pseudo-code for it | One candidate, SDE II | Finish a design by sketching the core class or algorithm, not only boxes. |
| A rejection after treating a design round like a coding problem, and being pressed on experience at scale | One candidate, 2022 | Start from requirements and trade-offs, and tie your choices to something you have run in production, if you have. |
Candidate posts and prep-site lists name prompts like these. First-hand posts are evidence of what one person was asked. Prep-site lists are guesses by other companies, which makes them good practice and weak evidence.
| Prompt, as reported | Reported by | What it really tests | Start from |
|---|---|---|---|
| A chat system for millions of users, Teams-style | Prep-site lists | Real-time connections, ordering, fan-out | Worked below |
| Cloud file storage and sync, OneDrive-style. Ask whether it is consumer or enterprise first | Prep-site lists | Chunking, deduplication, conflicts, sync cursors | The file sync design in the first guide |
| A notification service | Prep-site lists | Queues, retries, idempotency | Queues and asynchronous work |
| An in-memory cache library with a swappable eviction policy, with the focus on multithreading | Candidate reports, senior | Interfaces, eviction, locking | Worked below |
| An API that handles many query types | Candidate reports, senior | API shape, pagination, versioning, limits | Rate limiting and the API cards in the URL shortener |
| An alarm system with create, read, update and delete operations | Candidate report, SDE II | Scheduling at scale, durability | Queues and asynchronous work |
| A coding contest platform | Candidate report, SDE II | Running untrusted code, queues, leaderboards | Queues and caching |
The last two have the same shape as everything else: requirements first, a small high-level design, then the two or three places it breaks. An alarm system is, in effect, a reminder service: a durable store keyed by due time, a scheduler that loads the next minute's alarms into a delay queue, and workers that fire each one at least once with an idempotency key. A contest platform is a submission queue, sandboxed workers with CPU, memory and time limits, and a cache for the leaderboard. Each deserves its own page. The two designs below are the ones that teach the most reusable ideas.
A Teams-style chat service, designed from the requirements up. This is our design for practice, not Microsoft's architecture.
Requirements. One-to-one and group conversations, channels with many members, message history, delivery and read state, online status, and notifications for people who are away. It must feel instant, well under a second, keep messages in order within a conversation, never lose a message it has acknowledged, and stay available when a server fails. Enterprise customers also ask for retention rules, legal hold, tenant isolation and data residency, which change how storage and deletion work.
Numbers. Illustrative, so the design has a scale to be judged against. 10 million daily users sending 40 messages each is 400 million messages a day: about 4,600 a second on average, and perhaps 23,000 a second at a peak five times higher. At about 1 KB per message with metadata, that is roughly 400 GB a day, or 146 TB a year before replication. If a fifth of daily users are connected at once, that is 2 million open connections. At about 50,000 connections per gateway server, a figure that depends heavily on hardware and tuning, that is around 40 gateways.
The decisions that matter, each with its cost:
- Connections. Devices keep a WebSocket open to a gateway, a stateful tier that authenticates, checks heartbeats and pushes messages down the connection. Gateways hold connections and nothing else, so one can fail and its clients reconnect to another. A small registry, kept in a cache, records which gateway holds which user, with an expiry refreshed by heartbeats.
- Ordering. Device clocks disagree, so timestamps cannot order messages. The chat service gives each message the next sequence number in its conversation (1207 after 1206), and each conversation is owned by one partition, so one writer hands out the numbers. The cost is that one conversation's writes pass through one place, which is fine because people type slowly. The failover cost is covered in the senior follow-ups.
- Delivery. The network can lose an acknowledgement, so senders retry. Make sending idempotent: the device attaches its own message id, and the service returns the same sequence number for a repeated id. Deliver at least once, and let the receiving device ignore anything at or below the sequence it has already seen. Exactly-once delivery over a network is not on offer. Exactly-once effect is, and the sequence number is how you get it.
- Offline and many devices. Each device remembers the last sequence it saw in each conversation and, when it reconnects, asks for everything after it. The same call serves a phone that was switched off, a second laptop and a brand-new sign-in.
- Fan-out. For a group of a few dozen, publish one event per message and let it reach every connected member's gateway. For a channel with 100,000 members, one delivery per member is 100,000 writes for every message, so send members only a light "new activity" signal and let their clients fetch when they look. Say where your cut-off is and why.
- Presence. Heartbeats refresh a short expiry in a cache, and no heartbeat means no longer online. Presence is the chattiest data in a chat product, so send changes only to people who currently have that person on screen.
- Storage. Messages are append-mostly, read as "the latest N" or "everything after S", and almost never updated. Partition by conversation id with the sequence as the sort key, so both reads are range scans inside one partition. For a very busy conversation, add a time bucket to the partition key so that no partition grows without bound.
conversation_idbigint
partition key
PKseqbigint
1, 2, 3 ... per conversation, assigned by the chat service
PKclient_msg_idtext
chosen by the sending device, makes retries safe
UNIQUEsender_idbigint
bodytext
sent_attimestamp
for display only, never for ordering
edited_attimestamp
NULLdeletedbool
a soft delete, so retention rules can be applied later
Both reads, "the latest 50" and "everything after seq S", are range scans inside one partition.
user_idbigint
PKdevice_idtext
each device keeps its own cursor
PKconversation_idbigint
PKlast_seen_seqbigint
what this device has already received
last_read_seqbigint
unread count = latest sequence minus this
- auth
- bearer token
- idempotency
- client_message_id in the body, the same id returns the same message
- body
- { "client_message_id": "c-981", "body": "hello" }
- 201stored, returns { "seq": 1207, "message_id": "..." }
- 403not a member of the conversation
- 429sending too fast
- note
- how a device catches up after being offline, and how history is paged
- 200messages with a sequence greater than 1200, oldest first, plus the latest sequence
- 403not a member of the conversation
Enterprise requirements land mostly in storage. Retention means a deletion job that respects per-tenant rules. Legal hold means that job must skip held items. Data residency means a tenant's conversations live in one region. A soft deleted flag and a tenant id on every row make all three possible without a redesign.
Candidates report this prompt for senior roles: design an in-memory cache library whose eviction policy can be swapped, with the focus on multithreading. It is a class-design question, so the answer is interfaces first and algorithms second.
The shape. The cache owns the data and the capacity. A policy object owns only the ordering: it is told when a key is added, accessed or removed, and asked which key to evict. That single interface is what makes policies swappable, and it keeps LRU and LFU logic out of the cache.
LRU and LFU. Least recently used evicts the key that has been untouched the longest. A linked list ordered by recency, plus a dictionary from key to list node, makes every operation O(1). Least frequently used evicts the key used the fewest times, breaking ties by recency. A dictionary from a use count to a list of keys, plus the lowest count in use, gives O(1) amortised.
C# · IEvictionPolicy, LruPolicy
using System;
using System.Collections.Generic;
public interface IEvictionPolicy<TKey>
{
void OnAdd(TKey key); // a new key was stored
void OnAccess(TKey key); // an existing key was read or overwritten
void OnRemove(TKey key); // a key left the cache, evicted or removed
TKey PickVictim(); // which key to evict next
}
public sealed class LruPolicy<TKey> : IEvictionPolicy<TKey>
{
private readonly LinkedList<TKey> _order = new(); // most recent at the front
private readonly Dictionary<TKey, LinkedListNode<TKey>> _nodes = new();
public void OnAdd(TKey key) => _nodes[key] = _order.AddFirst(key);
public void OnAccess(TKey key)
{
LinkedListNode<TKey> node = _nodes[key];
_order.Remove(node);
_order.AddFirst(node);
}
public void OnRemove(TKey key)
{
if (_nodes.Remove(key, out LinkedListNode<TKey> node)) _order.Remove(node);
}
public TKey PickVictim() => _order.Last.Value; // the least recent
}C# · LfuPolicy
using System.Collections.Generic;
public sealed class LfuPolicy<TKey> : IEvictionPolicy<TKey>
{
private readonly Dictionary<TKey, int> _count = new();
private readonly Dictionary<TKey, LinkedListNode<TKey>> _nodes = new();
private readonly Dictionary<int, LinkedList<TKey>> _byCount = new(); // count -> keys, most recent first
private int _lowest; // never above the real lowest count
public void OnAdd(TKey key)
{
_count[key] = 1;
_nodes[key] = Bucket(1).AddFirst(key);
_lowest = 1;
}
public void OnAccess(TKey key)
{
int n = _count[key];
Detach(key, n);
_count[key] = n + 1;
_nodes[key] = Bucket(n + 1).AddFirst(key);
}
public void OnRemove(TKey key)
{
if (!_count.TryGetValue(key, out int n)) return;
Detach(key, n);
_count.Remove(key);
_nodes.Remove(key);
}
public TKey PickVictim()
{
while (!_byCount.ContainsKey(_lowest)) _lowest++; // skip counts nobody has now
return _byCount[_lowest].Last.Value; // least recent among the least used
}
private LinkedList<TKey> Bucket(int n)
{
if (!_byCount.TryGetValue(n, out LinkedList<TKey> list)) _byCount[n] = list = new LinkedList<TKey>();
return list;
}
private void Detach(TKey key, int n)
{
LinkedList<TKey> list = _byCount[n];
list.Remove(_nodes[key]);
if (list.Count == 0) _byCount.Remove(n);
}
}The cache itself knows nothing about LRU or LFU. It takes a lock around every operation. Note that even a read changes state, because recency and frequency are state, so reads need the lock too. A reader-writer lock would not help.
C# · Cache
using System;
using System.Collections.Generic;
public sealed class Cache<TKey, TValue>
{
private readonly int _capacity;
private readonly IEvictionPolicy<TKey> _policy;
private readonly Dictionary<TKey, TValue> _items = new();
private readonly object _gate = new();
public Cache(int capacity, IEvictionPolicy<TKey> policy)
{
if (capacity <= 0) throw new ArgumentOutOfRangeException(nameof(capacity));
_capacity = capacity;
_policy = policy;
}
public int Count { get { lock (_gate) return _items.Count; } }
public bool TryGet(TKey key, out TValue value)
{
lock (_gate)
{
if (!_items.TryGetValue(key, out value)) return false;
_policy.OnAccess(key);
return true;
}
}
public void Set(TKey key, TValue value)
{
lock (_gate)
{
if (_items.ContainsKey(key))
{
_items[key] = value;
_policy.OnAccess(key);
return;
}
if (_items.Count == _capacity)
{
TKey victim = _policy.PickVictim();
_items.Remove(victim);
_policy.OnRemove(victim);
}
_items[key] = value;
_policy.OnAdd(key);
}
}
public bool Remove(TKey key)
{
lock (_gate)
{
if (!_items.Remove(key)) return false;
_policy.OnRemove(key);
return true;
}
}
}The first test replays the same traffic against both policies. They evict different keys, which is the point of making the policy swappable. The last test hammers one cache from eight threads.
C#
using System;
using System.Diagnostics;
using System.Threading.Tasks;
static void Traffic(Cache<string, int> cache)
{
cache.Set("a", 1);
cache.Set("b", 2);
cache.TryGet("a", out _);
cache.TryGet("a", out _); // a: used 3 times, most recently two steps ago
cache.TryGet("b", out _); // b: used 2 times, most recently now
cache.Set("c", 3); // full: something must go
}
var lru = new Cache<string, int>(2, new LruPolicy<string>());
Traffic(lru);
bool lruKeptA = lru.TryGet("a", out _);
bool lruKeptB = lru.TryGet("b", out _);
Debug.Assert(!lruKeptA && lruKeptB); // LRU drops a: b was touched more recently
var lfu = new Cache<string, int>(2, new LfuPolicy<string>());
Traffic(lfu);
bool lfuKeptA = lfu.TryGet("a", out _);
bool lfuKeptB = lfu.TryGet("b", out _);
Debug.Assert(lfuKeptA && !lfuKeptB); // LFU drops b: a was used more often
var small = new Cache<int, int>(2, new LfuPolicy<int>());
small.Set(1, 1);
small.Set(2, 2);
bool removed = small.Remove(1);
bool removedAgain = small.Remove(1);
Debug.Assert(removed && !removedAgain);
small.Set(3, 3); // there is room again: nothing is evicted
Debug.Assert(small.Count == 2);
var shared = new Cache<int, int>(50, new LruPolicy<int>());
Parallel.For(0, 8, thread =>
{
var random = new Random(thread);
for (int i = 0; i < 20000; i++)
{
int key = random.Next(200);
if (!shared.TryGet(key, out _)) shared.Set(key, key);
}
});
Debug.Assert(shared.Count <= 50); // never over capacity, and nothing threwThread safety, honestly. One lock is correct and simple, and it is the right first answer. When that lock becomes the limit, there are three next steps, and a senior answer names the trade of each:
- Shard the cache. Several caches, each with its own lock and policy, chosen by a hash of the key. Contention drops by the number of shards. Eviction becomes approximate, because each shard evicts on its own.
- Batch the policy updates. Record reads in a buffer and apply them to the policy in batches under the lock, so a read does not wait for the ordering work. High-performance caches such as Caffeine for Java take this approach.
- Keep loading off the lock. On a miss, the value usually comes from a slow source. Do not hold the lock while loading, and make concurrent requests for the same missing key share one load, so a popular key that expires does not send a hundred requests to the database at once.
The natural extension is expiry: store a deadline with each value, treat an expired entry as a miss when it is read, and sweep in the background, using a min-heap or a timing wheel to find what expires next.
Interviewer follow-upL5A user has three devices and sends from two of them. How do you keep the messages in order?How to answer
Order comes from the service, not from the devices. Each message gets the next sequence number in its conversation when it is stored, and every device displays by that number. A message typed while offline waits as "sending" and takes its place when it reaches the service, so the order is the order of arrival at the service, not the order of typing. That is also what users expect in practice.
Interviewer follow-upL6A channel has 200,000 members. What breaks, and what do you change?How to answer
One delivery per member per message, per-member unread counters and presence updates all multiply by 200,000. Move large channels to a pull model: send a light "new activity" signal and let clients fetch after their cursor when they look. Compute unread counts from the difference between the latest sequence and the member's cursor, instead of keeping a counter per member. Limit presence to people on screen, and rate-limit posting and mentions.
Interviewer follow-upL6A gateway dies while holding 50,000 connections. What happens?How to answer
Clients see the connection drop and reconnect through the load balancer to any gateway, then ask for everything after their cursor, so nothing is lost. The registry entry for the dead gateway expires on its own. The real danger is a reconnect storm: 50,000 clients retrying in the same second. Use jittered backoff on the client, a connection-rate limit on the gateways, and enough spare capacity to absorb the surge.
Interviewer follow-upL6Two threads miss on the same key at the same time. What does your cache do?How to answer
With the code above, both go to the slow source and both store the result, which wastes work and, for a popular key, can overload the source. Keep a map of loads in progress, so the second thread waits for the first thread's result instead of starting its own. Remove the entry when the load finishes, and decide what a failed load does: let the next caller retry, rather than caching the failure forever.
Interviewer follow-upL7The conversation's owner fails over. How do you stop two writers handing out the same sequence number?How to answer
Make ownership a lease with an epoch number that increases each time ownership changes, and have the store reject any append that carries an older epoch. This is a fencing token. A stale owner that has not noticed it lost the lease then fails on its next write, instead of corrupting the sequence. The new owner also starts counting from the last sequence in the store, not from anything held in memory.
Interviewer follow-upL7A customer requires that its messages never leave the EU, and a legal hold on one user. What changes?How to answer
Pin each tenant to a home region and route all of its conversations there, including the message store, search index, caches and backups. A legal hold means deletion and compaction must skip held items, so deletion becomes a soft flag plus a job that checks retention rules and holds before anything is removed. The hard part is conversations that include people from other tenants or regions, so decide up front which tenant's rules govern a shared conversation and say so.
Treat the reported prompts as themes: a chat service, file sync, notifications, a cache library, and a few smaller systems. For chat, order messages with a per-conversation sequence number, deliver at least once and let devices drop duplicates, sync from cursors, and fan out differently for small groups and huge channels. For the cache library, put eviction behind an interface, protect the state with one lock first, and know the three ways to go beyond it. Then practise answering the follow-up before it is asked.
Try answering out loud before you reveal each answer.
QuestionWhich parts of what you read about Microsoft's design round are published, and which are reported?Reveal answer
Published: the short interview of about 45 minutes, the topics it names, and the advice to clarify, plan, think aloud and check your work. Reported: the specific prompts, the number of rounds, and the mix of design and class design. Treat reported details as anecdotes and confirm structure with your recruiter.
QuestionWhy does the chat design order messages with a per-conversation sequence number instead of timestamps?Reveal answer
Device clocks disagree, so timestamps can order messages wrongly. One owner per conversation hands out consecutive numbers, which gives a single order every device can agree on, makes duplicates easy to drop, and lets a device sync by asking for everything after its last number.
QuestionWhy does a cache's read operation need the lock, and what does that mean for a reader-writer lock?Reveal answer
Recency and frequency are state, and a read updates them, so a read is a write as far as the policy is concerned. A reader-writer lock would force every read to take the exclusive side, so it would not help. Sharding or batching the policy updates reduces contention instead.
- Microsoft Careers, Technical interviewing (opens in a new tab) and Interview tips (opens in a new tab). Some pages are several years old.
- Public candidate reports of the kind this guide draws on, anonymous and unverified: LeetCode Discuss, Microsoft hiring event, Redmond, May 2022, SDE III (opens in a new tab) and Microsoft SDE III, Redmond, 2022 (opens in a new tab), and GeeksforGeeks, Microsoft interview experience for SDE-II (opens in a new tab).
- Prep-site lists that name the Teams-style and OneDrive-style prompts, such as Educative (opens in a new tab) and Interview Kickstart (opens in a new tab). These are third-party guesses, not Microsoft sources.
- Caffeine, Design (opens in a new tab): how a high-performance cache records reads in buffers and applies policy updates in batches.
- Martin Kleppmann, Designing Data-Intensive Applications (O'Reilly, 2017): ordering, replication and fencing tokens.