Fundamentals 15 min read

Technical Interview Insights: Networking, TCP, HTTP, MySQL Locks, and C++ Level‑Order Traversal

The article explains why network protocols use layered design, details TCP's reliability and congestion‑control mechanisms, outlines HTTP status‑code categories, reviews MySQL lock scopes from global to row‑level, provides a C++ breadth‑first binary‑tree traversal example, and describes a three‑step weighing puzzle to find an odd ball.

Java Tech Enthusiast
Java Tech Enthusiast
Java Tech Enthusiast
Technical Interview Insights: Networking, TCP, HTTP, MySQL Locks, and C++ Level‑Order Traversal

Network

Why network protocols need layering?

Layering isolates concerns so each layer handles a specific function, improving modularity, flexibility, and problem decomposition.

Layers are independent, allowing interface‑based interaction.

Each layer can use the most suitable technology, promoting high cohesion and low coupling.

Complex problems are broken into smaller, well‑defined sub‑problems.

TCP reliability mechanisms

TCP ensures reliable transmission through connection management, sequence numbers, acknowledgments, timeout retransmission, flow control, and congestion control.

Connection management : three‑way handshake and four‑way termination.

Sequence numbers : uniquely number each byte to detect loss, duplication, and ordering.

Acknowledgments : receiver returns ACK with the next expected sequence number.

Timeout retransmission : resend when ACK is not received within a timeout.

Flow control : sliding window limits sender speed to receiver’s processing capacity.

Congestion control : adjusts sending rate based on network congestion using algorithms such as slow start, congestion avoidance, fast retransmit, and fast recovery.

TCP congestion‑control logic

Slow start : begins with a small congestion window (cwnd) and grows exponentially with each ACK.

Congestion avoidance : after reaching a threshold, cwnd grows linearly.

Fast retransmit : on three duplicate ACKs, the missing segment is resent immediately.

Fast recovery : sets ssthresh to half of cwnd, then inflates cwnd to ssthresh plus three MSS, allowing quicker return to normal flow.

HTTP status codes

HTTP responses are grouped into five classes:

1xx – informational.

2xx – success (e.g., 200 OK).

3xx – redirection (e.g., 301, 302).

4xx – client errors (e.g., 404 Not Found, 405 Method Not Allowed).

5xx – server errors (e.g., 500 Internal Server Error).

MySQL Lock Types

MySQL locks are categorized by scope:

Global lock : FLUSH TABLES WITH READ LOCK makes the whole instance read‑only, used for logical backups.

Table‑level locks : table lock, metadata lock (MDL), intention lock.

Row‑level locks (InnoDB only): record lock (S/X), gap lock, next‑key lock.

Algorithm Example – Binary‑Tree Level‑Order Traversal

The following C++ code demonstrates a breadth‑first traversal using std::queue :

#include <iostream>
#include <queue>
using namespace std;
struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};
void levelOrderTraversal(TreeNode* root) {
    if (root == nullptr) return;
    queue
q;
    q.push(root);
    while (!q.empty()) {
        TreeNode* cur = q.front(); q.pop();
        cout << cur->val << " ";
        if (cur->left) q.push(cur->left);
        if (cur->right) q.push(cur->right);
    }
}

Logic Puzzle – Finding the Odd Ball

A three‑step weighing strategy can identify the unique ball among seven using a balance scale, regardless of whether it is heavier or lighter.

DatabaseC++TCPMySQLHTTPAlgorithmsnetworking
Java Tech Enthusiast
Written by

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!

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.