Comprehensive Backend Interview Guide: MySQL, Redis, Java Collections, Concurrency, and TCP

This article compiles essential backend interview questions and answers covering MySQL storage engines and indexes, Redis persistence modes, Java collection frameworks and HashMap internals, thread‑safe ConcurrentHashMap implementations, as well as HTTP message structure and TCP reliability mechanisms, providing a thorough review for candidates preparing for backend positions.

IT Services Circle
IT Services Circle
IT Services Circle
Comprehensive Backend Interview Guide: MySQL, Redis, Java Collections, Concurrency, and TCP

MySQL

Difference between NoSQL and SQL?

SQL databases are relational databases such as MySQL, PostgreSQL, Oracle, and SQL Server. They store structured data in tables where each column represents an attribute and each row represents an entity.

NoSQL databases like MongoDB and Redis store data in non‑relational formats such as JSON documents or hash tables.

Choosing between SQL and NoSQL depends on whether ACID guarantees are required; banking systems need ACID, while social apps can tolerate eventual consistency.

ACID vs. BASE

Relational databases support ACID (Atomicity, Consistency, Isolation, Durability). NoSQL adopts BASE (Basically Available, Soft state, Eventual consistency).

Scalability Comparison

NoSQL systems are easier to scale horizontally because they lack inter‑row relationships; Redis provides built‑in replication, sentinel, and cluster modes. Relational databases require complex distributed joins and transaction handling for horizontal scaling.

MySQL Storage Engines

MySQL mainly provides MyISAM, InnoDB, and MEMORY engines.

Transaction support: InnoDB supports transactions; MyISAM does not.

Foreign key support: Only InnoDB supports foreign keys.

Index and data storage: InnoDB uses clustered indexes (B+Tree) with data stored together; MyISAM stores index pointers separately.

File format: MyISAM creates .frm, .MYD, .MYI files; InnoDB can use shared or per‑table tablespaces.

Data safety: InnoDB provides crash recovery; MyISAM does not.

Clustered vs. Non‑Clustered Indexes

In InnoDB, clustered index leaf nodes store the full row data, allowing direct row access. Non‑clustered index leaf nodes store only the primary key, requiring a table lookup (back‑table) to retrieve the row.

Clustered index leaf nodes store rows; non‑clustered store primary‑key pointers.

Clustered indexes are faster; non‑clustered need an extra lookup.

Only one clustered index (the primary key) per table; multiple non‑clustered indexes are allowed.

Why B+ Tree?

MySQL uses B+ trees for indexes because leaf nodes store actual data, internal nodes only store keys, and leaf nodes are linked for efficient range queries. This structure reduces disk I/O compared to B trees and provides better insertion/deletion performance.

Can a Composite Index (a,b,c) be used when the query filters on a=2 and c=1?

Yes, the index can be used, but only the leading column a can be used for index lookup; c cannot because it violates the left‑most prefix rule. In MySQL 5.6+, index‑pushdown can reduce the amount of back‑table lookups.

Redis

Difference between RDB and AOF persistence

RDB creates point‑in‑time snapshots; it is compact and fast to load but may lose recent writes.

AOF appends every write command; it provides more complete data recovery at the cost of larger files and higher disk I/O.

Java

Java Collection Classes

List is ordered; common implementations are ArrayList, LinkedList, Vector, and Stack.

ArrayList: resizable array, fast random access, slower inserts/removes.

LinkedList: doubly‑linked list, fast inserts/removes, slower random access.

Set stores unique, unordered elements; implementations include HashSet, LinkedHashSet, and TreeSet.

HashSet uses a HashMap internally; not ordered.

LinkedHashSet preserves insertion order via a linked hash map.

TreeSet uses a TreeMap to keep elements sorted.

Map stores key‑value pairs; common implementations are HashMap, LinkedHashMap, TreeMap, Hashtable, and ConcurrentHashMap.

HashMap (pre‑JDK 8) uses array + linked list; JDK 8 switches to a red‑black tree when a bucket exceeds 8 entries.

LinkedHashMap adds a doubly‑linked list to preserve insertion order.

ConcurrentHashMap provides thread safety via segment locks (JDK 7) or CAS + synchronized (JDK 8).

How HashMap put/get works

put() computes the key’s hashCode, determines the bucket, and inserts the entry, resizing when the load factor is exceeded.

get() computes the hash, locates the bucket, and traverses the chain or tree, using equals() to find the matching key.

Why HashMap uses a Red‑Black Tree instead of AVL?

Red‑black trees provide balanced performance with fewer rotations, making insert/delete operations cheaper than the strictly balanced AVL trees, while still offering O(log n) lookup.

Is HashMap thread‑safe?

No. Concurrent modifications can cause infinite loops during resizing (JDK 7) or data loss (JDK 8). Synchronization or using ConcurrentHashMap is required for thread safety.

How ConcurrentHashMap ensures thread safety

JDK 7 uses segmented locks (Segment + HashEntry). JDK 8 replaces segments with a finer‑grained lock on each bucket and employs CAS for lock‑free writes when possible.

Network

HTTP Message Format

Requests consist of a request line, headers, an empty line, and an optional body. Responses consist of a status line, headers, an empty line, and a body.

Common HTTP Status Codes

1xx – informational, 2xx – success, 3xx – redirection, 4xx – client error, 5xx – server error. Typical codes: 200, 301, 302, 404, 405, 500.

Difference between 502 and 504

502 Bad Gateway: upstream server returned an invalid response.

504 Gateway Timeout: upstream server did not respond within the configured timeout.

Other HTTP Methods

PUT – update an existing resource.

DELETE – remove a resource.

HEAD – like GET but without a response body.

PATCH – partially modify a resource.

OPTIONS – list supported methods.

How TCP Guarantees Reliability

TCP uses connection management (three‑way handshake, four‑way termination), sequence numbers, acknowledgments, timeout retransmission, flow control (sliding window), and congestion control.

TCP Congestion Control Process

Four algorithms: Slow Start, Congestion Avoidance, Congestion Occurrence, and Fast Recovery.

Slow Start

cwnd starts at 1 MSS and grows exponentially (cwnd += 1 per ACK) until it reaches the slow‑start threshold (ssthresh).

Congestion Avoidance

When cwnd ≥ ssthresh, cwnd increases linearly (cwnd += 1/cwnd per ACK).

Congestion Occurrence

On timeout, ssthresh is set to cwnd/2 and cwnd is reset to 1, then Slow Start restarts.

Fast Recovery

On three duplicate ACKs, cwnd is reduced to cwnd/2, ssthresh is set to the new cwnd, and transmission continues with cwnd = ssthresh + 3 until a new ACK arrives.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

javaconcurrencyredisTCPmysqlinterview
IT Services Circle
Written by

IT Services Circle

Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.