Skip to content
Interview Prep

Backend interview notes

245 questions that come up in backend interviews, each with a short answer. Work through one section at a time or search across all of them, and tick a question off once you can explain it.

Core checklist

Operating Systems

0 of 24 reviewed

Processes & Threads

0/5 reviewed
  • Difference between process and thread

    A process is an independent program in execution with its own memory space (code, data, heap, stack); a thread is a lightweight unit of execution within a process that shares the process's memory and resources with other threads. Threads are cheaper to create/switch but less isolated — a crash in one thread can take down the whole process.

  • Context switching

    Saving the CPU state (registers, program counter, stack pointer) of the currently running process/thread and loading the state of the next one so the CPU can switch execution. It's pure overhead — no useful work is done during the switch — so frequent switching hurts throughput.

  • Process states (new, ready, running, waiting, terminated)

    New: process is being created. Ready: waiting for CPU allocation. Running: currently executing on CPU. Waiting/Blocked: waiting on I/O or an event. Terminated: finished execution and is being cleaned up by the OS.

  • Multithreading vs multiprocessing

    Multithreading runs multiple threads inside one process sharing memory — fast communication but needs synchronization and is limited by the GIL in some languages (e.g. CPython). Multiprocessing runs separate processes each with its own memory — better isolation and true parallelism, but higher overhead and IPC needed to communicate.

  • Thread synchronization basics

    Mechanisms (locks, mutexes, semaphores, condition variables, monitors) that coordinate access to shared data between threads so operations appear atomic and race conditions are avoided.

Memory Management

0/6 reviewed
  • Virtual memory concept

    An abstraction that gives each process its own private address space, mapped by the OS/MMU to physical RAM (and disk via swapping). It enables isolation between processes, allows programs larger than physical RAM, and simplifies memory allocation.

  • Paging and segmentation (high level)

    Paging divides memory into fixed-size pages/frames, avoiding external fragmentation but causing internal fragmentation. Segmentation divides memory into variable-size logical segments (code, stack, heap) matching program structure, which is more intuitive but prone to external fragmentation. Modern OSes often combine both.

  • Page replacement algorithms

    Algorithms that decide which page to evict from RAM when a new page must be loaded and memory is full, aiming to minimize future page faults.

  • LRU, FIFO

    LRU (Least Recently Used) evicts the page not used for the longest time — good hit rate but costlier to track. FIFO evicts the oldest-loaded page regardless of usage — simple but can perform poorly (Belady's anomaly).

  • Stack vs Heap memory

    Stack stores function call frames, local variables, and return addresses — fast, fixed-size, automatically managed (LIFO). Heap stores dynamically allocated memory — flexible size, manually or GC-managed, slower to allocate, and can fragment or leak.

  • Memory leaks and prevention

    A leak occurs when allocated memory is no longer needed but never freed/dereferenced, growing usage over time. Prevention: use RAII/smart pointers, garbage collection, close resources (files, connections) in finally/using blocks, and profile with tools like Valgrind or memory profilers.

Concurrency

0/7 reviewed
  • Race conditions

    Occur when two or more threads access shared data concurrently and at least one modifies it, with the outcome depending on timing/interleaving of execution. Fixed with proper locking or atomic operations.

  • Deadlocks

    A state where two or more threads/processes are each waiting on a resource held by the other, so none can proceed.

  • Necessary conditions (for deadlock)

    Mutual exclusion (resource held exclusively), hold and wait (holding one resource while waiting for another), no preemption (resources can't be forcibly taken), and circular wait (a cycle of processes each waiting on the next). All four must hold simultaneously for deadlock.

  • Prevention (of deadlock)

    Break one of the four necessary conditions: acquire all locks at once, impose a global lock ordering, allow preemption, use timeouts, or use deadlock detection/recovery algorithms (e.g. resource allocation graph, banker's algorithm).

  • Mutex vs Semaphore

    A mutex is a binary lock owned by the thread that acquired it, used for mutual exclusion of a single resource. A semaphore is a counter that can allow N threads to access a resource concurrently and can be signaled by a different thread than the one that waited — used for signaling and resource pooling, not just exclusion.

  • Critical section problem

    Ensuring that when multiple threads execute a section of code that accesses shared resources, only one runs it at a time. A solution must guarantee mutual exclusion, progress (no indefinite postponement), and bounded waiting (fairness).

  • Producer-consumer problem

    A classic synchronization problem where producer threads add items to a shared bounded buffer and consumer threads remove them; solved with semaphores/condition variables to block producers when the buffer is full and consumers when it's empty, avoiding race conditions.

CPU Scheduling

0/3 reviewed
  • FCFS, Round Robin, Priority scheduling

    FCFS (First-Come-First-Served) runs processes in arrival order — simple but can cause the convoy effect. Round Robin gives each process a fixed time quantum in rotation — fair and good for response time. Priority scheduling runs the highest-priority process first — can starve low-priority processes without aging.

  • Context switching overhead

    The CPU cycles spent saving/restoring state and flushing caches/TLB during a switch instead of running user code; too-frequent switching (e.g. very short time quanta) reduces effective throughput.

  • Preemptive vs non-preemptive

    Preemptive scheduling can forcibly suspend a running process to give the CPU to another (e.g. Round Robin, Priority with preemption) — better responsiveness. Non-preemptive lets a running process keep the CPU until it finishes or blocks (e.g. FCFS) — simpler but can hurt responsiveness.

File Systems & IPC

0/3 reviewed
  • Inodes, file permissions

    An inode is a data structure storing a file's metadata (size, owner, permissions, timestamps, pointers to data blocks) but not its name. Permissions (read/write/execute for owner/group/others) control access, represented as e.g. rwxr-xr-x or octal 755.

  • Hard vs soft links

    A hard link is another directory entry pointing to the same inode/data — deleting the original still leaves data accessible; can't span filesystems or link directories. A soft (symbolic) link is a separate file storing a path to the target — breaks if the target moves, but can span filesystems and link to directories.

  • Pipes, shared memory, message queues, sockets

    IPC mechanisms: pipes stream bytes between related processes (unidirectional, or bidirectional with named pipes). Shared memory maps the same physical memory into multiple processes for the fastest data exchange (needs external synchronization). Message queues let processes exchange discrete, structured messages via the kernel. Sockets enable communication between processes on the same or different machines over a network.