Skip to content

Web, Realtime & Media

Q (basic): What happens when you type a URL and press Enter?

Say this (30 sec):

  1. URL parsing. The browser checks its cache and the HSTS list.
  2. DNS lookup: browser cache, then OS cache, then the resolver (ISP or 1.1.1.1), which asks root, then TLD (.com), then the authoritative nameserver. Result: an IP address.
  3. TCP handshake (SYN, SYN-ACK, ACK). With HTTP/3, QUIC over UDP is used instead.
  4. TLS handshake: agree on the cipher, verify the certificate, exchange keys.
  5. The browser sends the HTTP request. It may pass through a CDN, load balancer, or reverse proxy before reaching the app server, which may query the DB.
  6. The response comes back: status, headers, and HTML.
  7. Rendering: parse HTML into the DOM and CSS into the CSSOM, build the render tree, then layout, paint, and composite. JS, CSS, and images trigger more requests.
Q (mid): How does DNS work? Record types?

Say this: DNS turns names into IPs through a hierarchy: recursive resolver, then root, then TLD, then authoritative server. Results are cached according to their TTL. Record types: A (IPv4), AAAA (IPv6), CNAME (alias to another name), MX (mail), TXT (verification, SPF), NS (nameservers).

Q (mid): Explain the TLS handshake at a basic level.

Say this (30 sec): In TLS 1.3: the client sends a ClientHello with supported ciphers and a key share. The server replies with a ServerHello, its own key share, and its certificate. The client checks the certificate chain up to a trusted CA and checks the domain name. Both sides derive the same symmetric session key with (EC)DHE key exchange. All later traffic uses fast symmetric encryption (AES-GCM or ChaCha20). TLS 1.3 needs 1 round trip (TLS 1.2 needed 2), and resumed connections can use 0-RTT.

Common wrong answer: “The data is encrypted with the server’s public key.” Asymmetric crypto is only used for authentication and key exchange. The bulk data uses symmetric keys.

Q (mid): HTTP/1.1 vs HTTP/2 vs HTTP/3?

Say this (30 sec):

  • HTTP/1.1: text-based, keep-alive connections, but only one outstanding request per connection in practice. Browsers open about 6 connections per host, and slow responses cause head-of-line blocking.
  • HTTP/2: binary framing and multiplexing of many requests over one TCP connection, plus HPACK header compression. Server push existed but browsers have dropped it. Problem: TCP-level head-of-line blocking. One lost packet stalls every stream.
  • HTTP/3: runs over QUIC (UDP). Streams recover from loss independently, the handshake combines transport and TLS 1.3 for faster setup, and connection migration keeps a connection alive when you switch from Wi-Fi to mobile data.
Q (mid): Explain Cache-Control and ETag.

Say this (30 sec):

  • Cache-Control: max-age=3600: fresh for 1 hour, no request needed. s-maxage is the same but for shared caches and CDNs.
  • public means a CDN may cache it. private means only the browser may.
  • no-cache: you may store it but must revalidate with the server before each use.
  • no-store: don’t store it at all (use this for sensitive data).
  • immutable: never changes. Use it with hashed filenames like app.3f9a.js.
  • ETag: a version fingerprint of the response. The browser sends If-None-Match: <etag>. If it hasn’t changed, the server returns 304 Not Modified with no body, which saves bandwidth. Last-Modified / If-Modified-Since is the older, time-based version.

Common wrong answer: “no-cache means don’t cache.” That’s no-store.

Q (basic): What is a CDN and how does it help?

Say this: A CDN is a network of edge servers around the world that cache content close to users. The first request misses and goes to the origin. Later requests hit the edge cache. Benefits: lower latency, less load on the origin, DDoS absorption, and TLS terminated at the edge. It works best for static assets and media segments. Use cache-busting (hashed filenames) or purges when content changes.

Q (mid): REST vs GraphQL vs RPC (gRPC/tRPC)?

Say this (30 sec):

  • REST: resources plus HTTP verbs. Simple, and HTTP caching works well. Can over-fetch or under-fetch, which leads to multiple round trips.
  • GraphQL: one endpoint, and the client asks for exactly the fields it needs. Great for complex UIs and mobile. Harder to cache, has N+1 risks (solved with DataLoader), and needs query cost limits.
  • RPC: calling functions. gRPC uses Protobuf over HTTP/2, is fast and strongly typed, and is common between microservices. tRPC and Hono RPC give TypeScript end-to-end type safety for full-stack TS apps.

I’d use REST for public APIs, GraphQL when many clients need different shapes of data, and gRPC for internal service-to-service calls.

Q (mid): Polling vs long polling vs SSE vs WebSockets?

Say this (30 sec):

  • Short polling: the client asks every N seconds. Simple but wasteful, with latency up to N.
  • Long polling: the server holds the request open until there’s data, then the client immediately sends a new one.
  • SSE (Server-Sent Events): one long HTTP response that streams events server-to-client only. The browser has a built-in EventSource API with auto-reconnect. Great for notifications, live feeds, and LLM token streaming.
  • WebSocket: starts with an HTTP Upgrade handshake, then becomes a full-duplex, persistent TCP connection. Use it for chat, multiplayer, and collaborative editing.

Follow-ups they ask: “Why not always WebSockets?” They’re stateful connections, so they’re harder to scale and load-balance, and some proxies have trouble with them. If data only flows server-to-client, SSE is simpler.

Q (mid): What is Socket.io? Is it the same as WebSocket?

Say this (30 sec): No. Socket.io is a library with its own protocol, built on Engine.IO. It uses WebSocket when possible and falls back to HTTP long-polling. By default it starts with polling and then upgrades. On top of that it adds auto-reconnection, named events, acknowledgements (callbacks), rooms, namespaces, and buffering while disconnected. Because of its protocol, a plain WebSocket client can’t connect to a Socket.io server.

Example:

io.on('connection', (socket) => {
socket.on('join', (roomId) => socket.join(roomId));
socket.on('message', ({ roomId, text }, ack) => {
socket.to(roomId).emit('message', { text, from: socket.id }); // everyone in the room except the sender
ack({ ok: true });
});
});
Q (mid): Rooms vs namespaces in Socket.io? Different emit types?

Say this: A namespace (/chat, /admin) is a separate channel over the same connection, with its own handlers and middleware. Rooms are server-side groups that sockets join and leave, used for things like a chat room or a user’s private channel (socket.join(userId)). Emits:

  • socket.emit: only this client.
  • io.emit: everyone.
  • socket.broadcast.emit: everyone except the sender.
  • io.to(room).emit: everyone in the room.
  • socket.to(room).emit: everyone in the room except the sender.
Q (tricky): How do you scale Socket.io across multiple servers?

Say this (30 sec): There are two problems. (1) Sticky sessions: with the polling transport, every request from one client must reach the same server. Configure the load balancer with IP hash or cookie affinity, or use WebSocket-only transport. (2) Cross-server broadcast: a user on server A must get messages emitted on server B. Use the Redis adapter (@socket.io/redis-adapter). It uses Redis pub/sub to send every emit to all servers, and each server delivers it to its local sockets.

Follow-ups they ask: “How do you authenticate sockets?” Send the token in the handshake (auth: { token }) and check it in io.use((socket, next) => ...) middleware.

Q (mid): What is HLS and how does it work?

Say this (30 sec): HTTP Live Streaming (from Apple) splits video into small segments of a few seconds each (.ts or fragmented MP4) and describes them in .m3u8 playlists.

  • The master (multivariant) playlist lists the available renditions, e.g. 360p, 720p, and 1080p, each with its BANDWIDTH and RESOLUTION.
  • Each media playlist lists the segment URLs for one rendition.

It’s plain HTTP, so it works with any CDN and normal caching. That’s a big advantage over older protocols like RTMP.

Example:

#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360
360p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720
720p/index.m3u8
Q (tricky): How does adaptive bitrate (ABR) decide the quality?

Say this (30 sec): The player decides, not the server. While it downloads segments, it measures throughput (segment size divided by download time, usually smoothed with something like an EWMA) and watches its buffer level. It chooses the highest rendition whose bitrate fits comfortably under the estimated bandwidth, with a safety margin. If the buffer is draining, it steps down. If bandwidth is high and the buffer is healthy, it steps up. Switches happen at segment boundaries. That works because all renditions are encoded with aligned keyframes (GOPs).

Common wrong answer: “The server detects the user’s connection speed and sends the right quality.”

Q (mid): What is Hls.js and why is it needed?

Say this: Only Safari (and iOS) plays HLS natively in <video>. Chrome and Firefox don’t. Hls.js is a JS library that downloads the playlists and segments, transmuxes them if needed, and feeds them to the <video> element through Media Source Extensions (MSE). It also runs the ABR logic. The usual pattern: if Hls.isSupported(), use Hls.js. Otherwise, if the browser can play application/vnd.apple.mpegurl natively, just set video.src.

Example:

if (Hls.isSupported()) {
const hls = new Hls();
hls.loadSource(url);
hls.attachMedia(video);
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = url;
}
Q (mid): How would you transcode video to HLS with FFmpeg?

Say this: FFmpeg decodes the input and re-encodes it, usually to H.264 video and AAC audio for compatibility. For HLS you make several renditions (scaled resolutions and bitrates) and segment them with -f hls. It’s CPU-heavy, so it runs in a background worker or job queue, never in the request handler, and never on Cloudflare Workers.

Example (single rendition):

Terminal window
ffmpeg -i input.mp4 -c:v libx264 -preset veryfast -b:v 2800k -vf scale=-2:720 \
-c:a aac -b:a 128k -g 48 -keyint_min 48 -sc_threshold 0 \
-hls_time 6 -hls_playlist_type vod -hls_segment_filename '720p_%03d.ts' 720p.m3u8

Follow-ups they ask: “Why -g 48 -sc_threshold 0?” It forces a fixed keyframe interval, so segments line up across renditions and ABR switching is clean. “Transcoding vs transmuxing?” Transcoding re-encodes (slow). Transmuxing only changes the container (fast), e.g. -c copy.

Q (mid): What role did Cloudinary play?

Say this (30 sec): Cloudinary is a managed media platform. I upload the video (ideally directly from the client with a signed upload, so my server doesn’t handle large files). Cloudinary transcodes it into HLS renditions using a streaming profile or automatic streaming (sp_auto), stores it, and serves it through its CDN. The player just loads the .m3u8 URL. This saves me from running and scaling my own FFmpeg workers and storage. The tradeoffs are cost per transformation and bandwidth, plus vendor lock-in.

Follow-ups they ask: “Why not do it yourself?” You could: FFmpeg workers, a queue, R2/S3 storage, and a CDN. That’s more control and cheaper at scale, but more work to run.

Q (mid): How would you build a content moderation pipeline for uploaded videos?

Say this (30 sec):

  1. The upload goes in with status “pending” and isn’t visible to others yet.
  2. A background job samples frames from the video, e.g. 1 frame every N seconds with FFmpeg, or Cloudinary’s frame extraction. Checking every frame is too expensive.
  3. Each frame goes to a classifier: NSFWJS (local or in the browser) and/or the Clarifai moderation API.
  4. Combine the scores, e.g. the maximum NSFW score across frames, or the number of frames over a threshold.
  5. Apply thresholds: above a high threshold, auto-reject. In a gray zone, send it to human review. Below a low threshold, approve.
  6. Store the scores and decision for auditing, and let users report content after it’s published.
Q (mid): What is NSFWJS? Where does it run?

Say this: NSFWJS is an open-source library that runs a pre-trained image classification model (MobileNet/Inception-based) with TensorFlow.js. It classifies an image into 5 classes: Drawing, Hentai, Neutral, Porn, Sexy, each with a probability. It can run in the browser (fast, private, but easy to bypass, since the client controls it) or on the server with @tensorflow/tfjs-node. For real enforcement, moderation must run server-side. Client-side checks are only a UX pre-filter.

Follow-ups they ask: “Why also Clarifai?” It’s a hosted API with larger, maintained models (it covers more categories like gore and drugs), so you get better accuracy without hosting a model. The costs are per-call pricing and latency. Using both gives a fast local first pass plus a stronger second opinion.

Q (tricky): How do you pick thresholds? What about false positives vs false negatives?

Say this (30 sec): A false positive blocks safe content, which frustrates users. A false negative lets bad content through, which is a safety and legal risk. Raising the threshold gives fewer false positives but more false negatives, and lowering it does the opposite. It’s a precision vs recall tradeoff. Pick thresholds by testing on a labeled sample of your real content, and use a two-threshold design with a human-review band in the middle. Watch for known weak spots: skin-heavy but safe content (beach, sports, medical, art) causes false positives, and short bad frames between sampled frames cause false negatives. Sampling more densely or using scene-change detection helps.

Common wrong answer: “The model is 9X% accurate so it’s reliable.” Accuracy alone is misleading when bad content is rare.