Fundamentals 14 min read

Key Questions for a Basic Infrastructure Interview: TCP, Redis, Kafka, CAP & More

This article compiles essential interview questions covering TCP connection termination, multi‑port listening, page load workflow, Redis data structures, Kafka consumer sizing and at‑most‑once semantics, the CAP theorem, Singleton usage, C++ map complexity, and a doubly linked list reversal algorithm, providing concise explanations and code examples.

macrozheng
macrozheng
macrozheng
Key Questions for a Basic Infrastructure Interview: TCP, Redis, Kafka, CAP & More

Basic Infrastructure Interview (Xiaohongshu)

1. Why does TCP have TIME_WAIT state?

TIME_WAIT ensures reliable connection closure. Only the active closer enters TIME_WAIT. It prevents old duplicate packets from being delivered to new connections and guarantees the passive closer receives the final ACK.

Prevents old packets with the same four‑tuple from being received by new connections.

Ensures the passive close side can receive the final ACK.

2. Can TCP listen on multiple ports simultaneously?

Yes. TCP can create multiple sockets, each bound to a different port, e.g., Nginx listening on 80 and 443.

3. What is the full process of opening a web page?

Parse URL and validate protocol and host.

Cache lookup (browser, OS, router, ISP DNS).

DNS resolution if cache miss.

Obtain MAC address via ARP or gateway.

Establish TCP connection (SYN, SYN‑ACK, ACK).

TLS handshake for HTTPS.

Send HTTP request.

Server processes request and returns response.

4. Redis data structures you should know

Redis provides five core types: String, Hash, List, Set, Sorted Set (Zset).

Later versions added Bitmap, HyperLogLog, GEO, Stream.

String – caching, counters, distributed lock, session.

List – simple message queue (with limitations).

Hash – object cache, shopping cart.

Set – set operations such as likes, common followers.

Zset – ranking, sorted results.

Bitmap – binary state statistics.

HyperLogLog – cardinality estimation.

GEO – geolocation (e.g., ride‑hailing).

Stream – durable message queue with consumer groups.

5. How many Kafka consumers should you use?

Consumer count should not exceed partition count. Each partition can be consumed by only one consumer in a consumer group.

Example: 6 partitions → up to 6 consumers; 8 consumers would leave 2 idle.

Formula: consumer number = min(partition count, expected throughput / per‑consumer capacity).

<code>consumer_number = min(partitions, throughput / consumer_capacity)</code>

For 12 partitions, 1000 msgs/s per consumer, 8000 msgs/s produce rate → need 8 consumers (≤12).

6. How does Kafka achieve “at most once” consumption?

Producer uses idempotent writes to avoid duplicate messages.

Consumer disables auto‑commit, manually commits offset after successful processing; if processing fails, offset is not committed.

7. What is the CAP theorem?

In a distributed system, Consistency, Availability, and Partition tolerance cannot all be achieved simultaneously; only two of the three can be guaranteed.

Consistency – all replicas see the same data at the same time.

Availability – system continues to serve reads/writes despite node failures.

Partition tolerance – system works despite network partitions.

8. Where is the Singleton pattern useful?

Global configuration management.

Logging – single logger instance.

Database connection pool.

9. C++ map insertion complexity

std::map is implemented as a red‑black tree; insertion time complexity is O(log n).

10. Reverse a doubly linked list (iterative)

<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
}</code>

Time complexity O(n), space complexity O(1).

distributed systemsbackend developmentdatabasesAlgorithmsfundamentals
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

login 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.