Technical Interview Q&A: TCP, Redis, Kafka, CAP Theorem, Singleton, C++ STL, and Algorithms
This guide reviews common backend interview topics, explaining TCP TIME_WAIT behavior, multi‑port listening, full page load steps, Redis data types, Kafka consumer sizing and at‑most‑once semantics, the CAP theorem, Singleton usage, C++ std::map complexity, and an O(n) doubly‑linked list reversal algorithm.
The article presents a collection of technical interview questions and answers covering backend development topics.
1. TCP TIME_WAIT – explains why the active closer enters TIME_WAIT to prevent old packets from affecting new connections and to ensure the passive side receives the final ACK.
2. Listening on multiple ports – TCP can listen on several ports by creating separate sockets (e.g., Nginx on 80 and 443).
3. Full page loading process – URL parsing, cache checks, DNS resolution, MAC address acquisition, TCP handshake, optional TLS handshake, HTTP request, server response.
4. Redis data structures – core types: String, Hash, List, Set, Zset; newer types: BitMap, HyperLogLog, GEO, Stream, with typical use cases.
5. Kafka consumer count – consumer number ≤ partition number. Example formula:
consumerCount = min(partitionCount, expectedThroughput / singleConsumerCapacity)Illustrated with a 12‑partition topic requiring 8 consumers for 8000 msg/s throughput.
6. Kafka “at most once” semantics – achieve by disabling auto‑commit and committing offsets only after successful processing.
7. CAP theorem – consistency, availability, partition tolerance cannot be simultaneously guaranteed; brief definitions provided.
8. Singleton pattern – ensures a single instance; typical scenarios: global configuration, logger, database connection pool.
9. C++ std::map complexity – implemented with a red‑black tree, insertion O(log n).
10. Doubly linked list reversal – iterative algorithm with O(n) time and O(1) space. Sample code:
public ListNode reverseDoublyLinkedList(ListNode head) {
if (head == null || head.next == null) {
return head;
}
ListNode prev = null;
ListNode current = head;
while (current != null) {
ListNode nextNode = current.next; // save next
current.next = prev; // reverse next
current.prev = nextNode; // reverse prev
prev = current;
current = nextNode;
}
return prev; // new head
}The content is primarily educational and useful for backend engineers preparing for interviews.
Java Tech Enthusiast
Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.