Comprehensive Interview Questions and Answers on Backend Development Topics
This article presents a collection of interview questions covering backend fundamentals such as linked‑list sorting, encryption differences, TCP reliability, IO models, Hystrix, delayed tasks, HTTPS flow, transaction isolation, index pitfalls, virtual memory, Redis leaderboards, distributed locks, zero‑copy techniques, Java synchronized, and Snowflake ID generation.
1. Sorting Linked List
Given the head of a linked list, sort it in ascending order using a two‑pointer merge sort approach, consisting of finding the middle node, splitting, recursively sorting sub‑lists, and merging them.
class Solution {
public ListNode sortList(ListNode head) {
if (head == null || head.next == null)
return head;
ListNode slow = head;
ListNode fast = head;
while (fast.next != null && fast.next.next != null) {
fast = fast.next.next;
slow = slow.next;
}
ListNode mid = slow.next;
slow.next = null;
ListNode left = sortList(head);
ListNode right = sortList(mid);
return merge(left, right);
}
public ListNode merge(ListNode left, ListNode right) {
ListNode head = new ListNode(0);
ListNode temp = head;
while (left != null && right != null) {
if (left.val <= right.val) {
temp.next = left;
left = left.next;
} else {
temp.next = right;
right = right.next;
}
temp = temp.next;
}
if (left != null) {
temp.next = left;
} else if (right != null) {
temp.next = right;
}
return head.next;
}
}2. Symmetric vs Asymmetric Encryption
Symmetric encryption uses the same key for encryption and decryption (e.g., AES, 3DES, DES, RC5, RC6). Asymmetric encryption uses a key pair—public key for encryption and private key for decryption (e.g., RSA, ElGamal, DSA, Diffie‑Hellman, ECC).
3. How TCP Guarantees Reliability
Three‑way handshake for connection establishment and four‑way handshake for termination.
Stateful tracking of sent, acknowledged, and missing packets to ensure ordered delivery.
Mechanisms such as checksums, ACKs, retransmission, duplicate suppression, flow control, and congestion control.
4. Five IO Models
4.1 Blocking IO
The calling thread blocks until the kernel has data ready and copies it to user space.
4.2 Non‑Blocking IO
The kernel returns immediately with an error if data is not ready; the application polls later.
4.3 IO Multiplexing (select/epoll)
select monitors multiple file descriptors and returns when any become ready; epoll improves scalability by using event‑driven callbacks.
4.4 Signal‑Driven IO
The kernel sends a signal (e.g., SIGIO) when data is ready, allowing the process to perform other work meanwhile.
4.5 Asynchronous IO (AIO)
The system call returns immediately, and the kernel notifies the application via a signal once the operation completes.
5. Hystrix Working Principle
Hystrix wraps a remote call in a command object (HystrixCommand or HystrixObservableCommand). Execution can be synchronous (execute) or asynchronous (queue, observe, toObservable). It provides circuit‑breaker, fallback, thread‑pool or semaphore isolation, and request caching.
6. Delay Task Handling Scenarios
JDK DelayQueue
Timing wheel algorithm
Database schedulers (e.g., Quartz)
Redis ZSet
Message‑queue delayed queues
7. HTTPS Request Process
User opens an HTTPS URL (connects to port 443).
Server presents its digital certificate (public key).
Client validates the certificate and generates a symmetric session key, encrypting it with the server’s public key.
Client sends the encrypted session key.
Server decrypts the session key with its private key and uses it to encrypt response data.
Client decrypts the response with the session key.
8. Transaction Isolation Levels and MVCC
Four isolation levels—Read Uncommitted, Read Committed, Repeatable Read, and Serializable—address dirty reads, non‑repeatable reads, and phantom reads. InnoDB implements Repeatable Read using MVCC with a Read View and Undo Log to provide a consistent snapshot.
9. Index Failure Scenarios
OR conditions in WHERE clause.
Missing quotes for string literals.
LIKE patterns that start with a wildcard.
Using non‑leading columns of a composite index.
Applying functions or arithmetic on indexed columns.
!=, <>, NOT IN, IS NULL/IS NOT NULL on indexed columns.
Different character sets in join conditions.
Optimizer decides a full table scan is cheaper.
10. Virtual Memory
Virtual memory gives each process its own address space, mapping virtual pages to physical memory. Benefits include address space larger than physical RAM and multiple virtual pages sharing the same physical page, enabling zero‑copy techniques.
11. Leaderboard Implementation
Redis ZSET (sorted set) is used; commands such as zadd key score member and zrank key member support ranking, with internal encodings like ziplist and skiplist.
12. Distributed Lock Implementations
Common approaches using Redis:
Separate SETNX and EXPIRE (prone to dead lock if crash occurs).
Store expiration timestamp as value and use GETSET to handle race conditions.
Atomic SET key value NX EX ttl (still vulnerable to premature expiration).
Same as above but store a unique request ID and delete only if the ID matches (often via Lua script).
Redisson library with a watchdog thread that automatically extends lock TTL.
13. Zero‑Copy Techniques
13.1 mmap + write
mmap maps a file into the process’s virtual address space, allowing the kernel buffer and user buffer to share the same physical memory, reducing CPU copies.
13.2 sendfile
sendfile transfers data between a file descriptor and a socket entirely in kernel space, eliminating user‑space copies.
13.3 sendfile + DMA scatter/gather
Modern Linux adds DMA scatter/gather to sendfile, removing the remaining CPU copy and achieving true zero‑copy.
14. synchronized Keyword and Monitor
synchronized can be applied to methods (adds ACC_SYNCHRONIZED flag) or blocks (generates monitorenter/monitorexit bytecode). The JVM uses an ObjectMonitor structure to manage ownership, wait sets, and entry queues.
15. Distributed ID Generation and Snowflake Algorithm
Common schemes include UUID, auto‑increment DB IDs, Snowflake, Baidu UidGenerator, and Meituan Leaf. Snowflake generates 64‑bit IDs: 1 sign bit, 41‑bit timestamp, 10‑bit machine ID, and 12‑bit sequence per millisecond.
Code Ape Tech Column
Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn
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.