Mid-Level Developer Interview Questions and Answers
Mid-level interviews focus on trade-offs and ownership. Interviewers want to see that you have hit real problems such as slow queries, race conditions or re-render storms, and know how to reason your way through them.
- What is the event loop in JavaScript and how does it work?
The event loop is the mechanism that lets single-threaded JavaScript handle asynchronous work: it runs the call stack to empty, then runs all queued microtasks (promises), then takes the next task (timers, events) from the queue.
- What is prototypal inheritance in JavaScript?
In JavaScript every object has an internal link to another object called its prototype, and property lookups walk up this prototype chain until the property is found or the chain ends.
- What is the difference between debounce and throttle in JavaScript?
Debounce waits until the user stops triggering an event for a set time before running the function; throttle runs the function at most once per time interval no matter how often the event fires.
- What is the difference between useMemo and useCallback in React?
useMemo caches the result of a calculation, while useCallback caches a function definition; both only recompute when their dependencies change.
- What is the difference between useRef and useState in React?
Updating state triggers a re-render, while changing a ref's .current value does not; use state for data shown on screen and refs for DOM access or values that must persist without causing renders.
- What is the difference between SSR, SSG and CSR in React?
CSR renders in the browser after JavaScript loads, SSR renders the HTML on the server for each request, and SSG renders the HTML once at build time; SSR and SSG give crawlers and users content faster, which helps SEO.
- What is the difference between async and defer on script tags?
Both download the script without blocking HTML parsing. defer waits until parsing finishes and runs scripts in document order; async runs a script as soon as it is downloaded, which can be before or after parsing and in any order.
- How does the browser render a web page?
The browser parses HTML into a DOM and CSS into a CSSOM, combines them into a render tree, computes layout (reflow), paints pixels and composites layers onto the screen.
- What is type narrowing in TypeScript?
Narrowing is when TypeScript shrinks a wide type (such as a union) to a more specific type after a runtime check like typeof, instanceof, in, or a custom type guard.
- What is the difference between enum and union types in TypeScript?
A string union such as "admin" | "user" exists only in the type system and erases to plain strings. A TypeScript enum compiles to a JavaScript object (unless it is a const enum), which is extra runtime code and a weaker default.
- How does TypeScript type inference work?
TypeScript fills in types you omit: literals get their literal or widened type, function return types are inferred from return statements, and generic arguments are inferred from the values you pass.
- What are ACID properties in a database?
ACID stands for Atomicity, Consistency, Isolation and Durability: a transaction either fully succeeds or fully fails, keeps the data valid, does not interfere with other transactions, and survives crashes once committed.
- What is an index in SQL and how does it improve performance?
An index is a separate sorted data structure (usually a B-tree) that lets the database find rows without scanning the whole table, at the cost of extra storage and slower writes.
- What is the difference between a clustered and a non-clustered index?
A clustered index defines the physical order in which the table's rows are stored, so there can be only one per table, while a non-clustered index is a separate structure that points back to the rows.
- What is the difference between IEnumerable and IQueryable in C#?
IEnumerable runs the query in memory using delegates, while IQueryable builds an expression tree that a provider such as Entity Framework translates into SQL, so filtering happens in the database.
- What are transient, scoped and singleton service lifetimes in ASP.NET Core dependency injection?
Transient services are created every time they are requested, scoped services are created once per HTTP request, and singleton services are created once and shared for the life of the application.
- What is the difference between Task and Thread, and how does async/await work in C#?
A Thread is an operating-system execution unit, while a Task represents an asynchronous operation scheduled on the thread pool; await releases the current thread while the operation is pending and resumes the method when it completes.
- How does garbage collection work in C# and when should you use IDisposable?
The .NET garbage collector automatically frees managed objects that are no longer reachable, organising them into generations 0, 1 and 2 so short-lived objects are collected cheaply, and IDisposable is used to release unmanaged resources such as files and connections promptly.
- How does HashMap work internally in Java?
A HashMap stores entries in an array of buckets; it computes the key's hash code to choose a bucket, resolves collisions with a linked list that becomes a red-black tree when a bucket grows large, and resizes when the load factor of 0.75 is exceeded.
- What is the difference between HashMap, Hashtable and ConcurrentHashMap in Java?
HashMap is not thread-safe, Hashtable is thread-safe by locking the whole map on every method, and ConcurrentHashMap is thread-safe with much finer-grained locking and lock-free reads, so it scales far better.
- How does JVM memory management and garbage collection work in Java?
The JVM divides memory into a per-thread stack, a shared heap (split into young and old generations) and Metaspace; the garbage collector frees heap objects that are no longer reachable, collecting short-lived young objects frequently and old objects less often.
- What are decorators in Python and how do they work?
A decorator is a function that takes another function and returns a modified version of it, letting you add behaviour such as logging, caching or access control without changing the original code.
- What are generators and the yield keyword in Python?
A generator is a function that uses yield to produce values one at a time and remembers its state between calls, so it can process large or infinite sequences without holding everything in memory.
- How does Python manage memory and garbage collection?
CPython frees objects mainly through reference counting, deleting an object as soon as nothing refers to it, and uses a cyclic garbage collector to clean up groups of objects that reference each other.
- What is the difference between process.nextTick, setImmediate and setTimeout in Node.js?
process.nextTick runs its callback right after the current operation, before the event loop continues; setTimeout runs in the timers phase after a minimum delay; and setImmediate runs in the check phase right after the poll (I/O) phase.
- What are streams in Node.js and why should you use them?
Streams process data piece by piece as it arrives instead of loading it all into memory, which lets you handle large files and network data efficiently; they come in Readable, Writable, Duplex and Transform types.
- What is the difference between JWT and session-based authentication?
Session authentication stores the login state on the server and gives the browser a session ID cookie, while JWT authentication gives the client a signed token that contains the user's claims so the server can verify it without storing state.
- How do you secure a Node.js Express API?
Validate all input, use parameterised queries, add security headers with helmet, rate-limit requests, restrict CORS, hash passwords, keep secrets in environment variables, and keep dependencies updated and audited.
- When should you use a SQL database vs a NoSQL database?
Choose SQL when your data is relational and you need transactions, joins and strong consistency; choose NoSQL when you need flexible schemas, very high write throughput or horizontal scaling for a specific access pattern.
- What is caching and what are the common cache invalidation strategies?
Caching stores frequently read data in fast storage such as memory to reduce latency and database load; the main strategies are cache-aside, write-through, write-back and time-based expiry (TTL).
- What is the difference between REST, GraphQL and gRPC?
REST exposes resources over HTTP URLs and is simple and cache-friendly, GraphQL lets clients ask for exactly the fields they need from a single endpoint, and gRPC uses binary Protocol Buffers over HTTP/2 for fast service-to-service calls.
- What is idempotency in REST APIs and why does it matter?
An operation is idempotent if repeating it any number of times has the same effect as doing it once; it matters because network retries can otherwise create duplicate orders or payments.
- How do you design a rate limiter?
Choose an algorithm such as token bucket or sliding window, store a counter per client (by user ID, API key or IP) in a fast shared store like Redis, and return HTTP 429 with a Retry-After header when the limit is exceeded.