Tiktok Interview Preparation
HR Interview
Q: Reason why you apply? what is your status now? A: Currently i'm working as Site Reliability Engineer in Shopee for around 2 years. Before take the SRE role, i spent my coding experience as a fullstack engineer. for my frontend stack, i having experience on developing with React & Vue. for the language commonly using Typescript now. For backend, mainly i just use 2 language Golang & Python.
Technical Skill
SRE Related
Q: What is SRE? A: SRE role is basically using software engineering skills to keep systems running smoothly and reliably. Apart from that i think SRE also responsible to maintain the SLA Metrics of a service also be the first frontline when an incident happening up until it got resolved
Q: Incident handling, do you ever encountered one before? How to handle it? SOP? A: During my times previously at Shopee, of course i already encounter multiple small incidents or a big incident that cause the server downtime. But my team always preparing a SOP for any incident that happening. In short, Our SOP is focusing on service recovery first. For example there are a incident that causing one of my services success rate dropping below 95% for more than 5 minutes. What we do usually is checking the Grafana first prior to anomaly metrics detected. Almost 80% of the incident can be detected by grafana. after i identified the anomaly metrics. Usually what i do is go to both log platform and Jaeger to trace which endpoint is affected. or is this issue causing downtime. For the root cause identification process. usually it can be caused from our middleware failure (DB, Cache, MQ), third-party failure (fraud-service, gameplatform). Or this can also caused if the compute resources not enough causing OOM
Q: Design a monitoring system for TikTok A: Okay, let's break this down. A monitoring system for TikTok needs to cover a lot of ground, given the scale and complexity. Here's a possible design:
-
Metrics Collection:
- Infrastructure Metrics: CPU usage, memory utilization, disk I/O, network traffic for all servers (using tools like Prometheus with node_exporter).
- Application Metrics:
- Request latency, error rates, request volume for all APIs (using Prometheus and application-level instrumentation).
- Database query performance (query execution time, number of queries, slow query logs).
- Cache hit/miss ratios (Redis, Memcached).
- Background job processing time and error rates.
- User Experience Metrics:
- Video upload time, video playback start time, buffering rate (collected from the client-side).
- Login success/failure rates.
- Search query latency and success rates.
- Feed load times.
- Business Metrics:
- Active users (DAU/MAU).
- Video views, likes, shares, comments.
- Ad impressions, click-through rates.
-
Data Aggregation and Storage:
- Use a time-series database like Prometheus or VictoriaMetrics to store metrics.
- Aggregate logs using tools like Elasticsearch, Loki, or Graylog.
- Consider using a distributed tracing system like Jaeger or Zipkin to trace requests across services.
-
Visualization and Alerting:
- Use Grafana to create dashboards for visualizing metrics.
- Set up alerts in Prometheus Alertmanager or Grafana to notify on-call engineers of issues. Alerts should be based on SLOs (Service Level Objectives). Examples:
- API error rate > 1%
- Video playback start time > 2 seconds
- 99th percentile latency > 500ms
-
Specific Monitoring Points:
- Content Delivery Network (CDN): Monitor CDN performance (cache hit ratio, latency, bandwidth).
- Recommendation System: Monitor the performance of the recommendation algorithms (click-through rate, engagement metrics).
- Search Infrastructure: Monitor search query latency and relevance.
- Live Streaming: Monitor live streaming quality (buffering, latency).
- Security: Monitor for suspicious activity (failed login attempts, unusual traffic patterns).
-
Tools:
- Prometheus: For collecting and storing metrics.
- Grafana: For visualization and dashboards.
- Alertmanager: For alerting.
- Elasticsearch/Loki/Graylog: For log aggregation and analysis.
- Jaeger/Zipkin: For distributed tracing.
- Kafka: For streaming data.
-
Key Metrics to Watch:
- Error Rates: Track error rates for all APIs and services.
- Latency: Monitor request latency at various points in the system.
- Saturation: Monitor resource utilization (CPU, memory, disk) to identify potential bottlenecks.
- Traffic: Monitor network traffic to detect anomalies.
This is a high-level overview, of course. The specific implementation would depend on TikTok's architecture and specific requirements.
OS
Q: What is the OSI Model? A: The OSI (Open Systems Interconnection) model is a conceptual framework that describes how data travels across a network. It divides the process into seven layers, each with specific functions:
- Physical Layer: Deals with the physical cables or wireless signals. It transmits raw data bits.
- Data Link Layer: Handles error-free transmission between two directly connected nodes. It uses MAC addresses.
- Network Layer: Determines the best path for data packets to travel from source to destination. IP addresses are used here.
- Transport Layer: Provides reliable or unreliable data delivery between processes. TCP and UDP operate at this layer.
- Session Layer: Manages connections between applications.
- Presentation Layer: Handles data formatting, encryption, and decryption.
- Application Layer: Provides network services to applications, like HTTP, DNS, and SMTP.
Network Concepts
Q: Describe the structure of URL A: A URL (Uniform Resource Locator) is a string of characters that provides a standardized way to locate a resource on the web. It's composed of several parts:
- Scheme: Indicates the protocol used to access the resource (e.g.,
http
,https
,ftp
). - Authority: Contains the following components:
- User Info (optional): Username and password (e.g.,
username:password@
). Discouraged for security reasons. - Host: The domain name or IP address of the server hosting the resource (e.g.,
www.example.com
). - Port (optional): The port number used to connect to the server (e.g.,
:8080
). If not specified, the default port for the scheme is used (e.g., 80 for HTTP, 443 for HTTPS).
- User Info (optional): Username and password (e.g.,
- Path: Specifies the location of the resource on the server (e.g.,
/path/to/resource.html
). - Query (optional): Contains parameters passed to the server (e.g.,
?param1=value1¶m2=value2
). - Fragment (optional): Identifies a specific part or section within the resource (e.g.,
#section-name
). Used by the browser to jump to that section.
Example: https://www.example.com:8080/path/to/resource.html?param1=value1¶m2=value2#section-name
Q: HTTP & HTTPS, TCP/IP Protocols A:
HTTP (Hypertext Transfer Protocol) and HTTPS (HTTP Secure) are protocols used for transferring data over the internet. TCP/IP (Transmission Control Protocol/Internet Protocol) is a suite of communication protocols used to interconnect network devices on the internet. Let's break them down:
HTTP:
- Definition: HTTP is the foundation of data communication on the web. It's an application-layer protocol that defines how messages are formatted and transmitted.
- Functionality: It enables communication between web browsers and web servers. When you type a URL into your browser, it sends an HTTP request to the server. The server then responds with the requested data, which the browser displays.
- Port: By default, HTTP uses port 80.
- Security: HTTP is not encrypted, meaning data transmitted over HTTP can be intercepted and read by attackers.
HTTPS:
- Definition: HTTPS is the secure version of HTTP. It adds a layer of security by encrypting the data transmitted between the browser and the server.
- Functionality: HTTPS uses SSL/TLS (Secure Sockets Layer/Transport Layer Security) to encrypt the communication. This ensures that even if the data is intercepted, it cannot be read without the decryption key.
- Port: By default, HTTPS uses port 443.
- Security: HTTPS provides confidentiality, integrity, and authentication, making it much more secure than HTTP.
TCP/IP:
- Definition: TCP/IP is a suite of protocols that govern how data is transmitted over the internet. It's the fundamental protocol suite that enables communication between devices on a network.
- Layers: The TCP/IP model consists of four layers:
- Application Layer: Provides network services to applications (e.g., HTTP, FTP, SMTP).
- Transport Layer: Provides reliable or unreliable data delivery between processes (e.g., TCP, UDP).
- Internet Layer: Handles addressing and routing of data packets (e.g., IP).
- Network Access Layer: Handles physical transmission of data (e.g., Ethernet, Wi-Fi).
- TCP (Transmission Control Protocol):
- Provides reliable, ordered, and error-checked delivery of data.
- Uses a three-way handshake to establish a connection and a four-way handshake to terminate it.
- Suitable for applications that require reliable data transmission (e.g., web browsing, email).
- UDP (User Datagram Protocol):
- Provides unreliable, unordered delivery of data.
- Does not establish a connection before transmitting data.
- Suitable for applications that can tolerate some data loss (e.g., streaming, online gaming).
- IP (Internet Protocol):
- Handles addressing and routing of data packets between networks.
- Each device on the internet is assigned a unique IP address.
In summary, HTTP and HTTPS are application-layer protocols used for web communication, while TCP/IP is a suite of protocols that governs how data is transmitted over the internet. HTTPS provides a secure version of HTTP by encrypting the data using SSL/TLS. TCP provides reliable data transmission, while UDP provides unreliable data transmission.
Q: Explain about three-hand shake greeting and four handshake termination in TCP A:
The Transmission Control Protocol (TCP) uses a three-way handshake to establish a connection between a client and a server, and a four-way handshake to terminate the connection.
Three-Way Handshake (Connection Establishment):
- SYN (Synchronize):
- The client sends a SYN packet to the server, indicating that it wants to establish a connection.
- This packet includes the client's initial sequence number (ISN), which is a random number used to track the data flow.
- SYN-ACK (Synchronize-Acknowledge):
- The server responds with a SYN-ACK packet, acknowledging the client's SYN packet and also indicating its own initial sequence number (ISN).
- This packet includes both the server's SYN and an acknowledgment of the client's SYN (ACK).
- ACK (Acknowledge):
- The client sends an ACK packet back to the server, acknowledging the server's SYN-ACK packet.
- This completes the three-way handshake, and the TCP connection is established.
Four-Way Handshake (Connection Termination):
- FIN (Finish):
- The client sends a FIN packet to the server, indicating that it wants to close the connection.
- This means the client has no more data to send.
- ACK (Acknowledge):
- The server sends an ACK packet back to the client, acknowledging the client's FIN packet.
- This indicates that the server has received the request to close the connection.
- FIN (Finish):
- The server sends a FIN packet to the client, indicating that it also wants to close the connection.
- This means the server has no more data to send.
- ACK (Acknowledge):
- The client sends an ACK packet back to the server, acknowledging the server's FIN packet.
- This completes the four-way handshake, and the TCP connection is terminated.
Q: What happen when you visit a website? A:
Okay, let's break down what happens when I visit a website, step by step:
-
Enter URL: You type a URL (e.g.,
www.example.com
) into your web browser's address bar and press Enter. -
DNS Resolution:
- The browser needs to find the IP address associated with the domain name (
www.example.com
). - It first checks its local cache, then the operating system's cache.
- If not found, it queries a DNS (Domain Name System) server, starting with a recursive DNS resolver (usually provided by your ISP).
- The resolver may query root servers, top-level domain (TLD) servers (e.g.,
.com
), and finally the authoritative name server forexample.com
to get the IP address. - The DNS resolver returns the IP address to your browser.
- The browser needs to find the IP address associated with the domain name (
-
TCP Connection:
- The browser initiates a TCP connection with the web server at the obtained IP address, typically on port 80 (for HTTP) or 443 (for HTTPS).
- This involves a three-way handshake:
- SYN: The browser sends a SYN (synchronize) packet to the server.
- SYN-ACK: The server responds with a SYN-ACK (synchronize-acknowledge) packet.
- ACK: The browser sends an ACK (acknowledge) packet to the server.
-
HTTP/HTTPS Request:
- Once the TCP connection is established, the browser sends an HTTP or HTTPS request to the server.
- For example:
GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) ... - If it's an HTTPS request, the browser and server negotiate a secure connection using SSL/TLS before sending the HTTP request. This involves exchanging certificates and establishing encryption keys.
-
Server Processing:
- The web server receives the request and processes it.
- It may retrieve the requested resource (e.g.,
index.html
) from its file system or generate it dynamically. - The server may also interact with databases or other backend systems to fulfill the request.
-
HTTP/HTTPS Response:
-
The server sends an HTTP or HTTPS response back to the browser.
-
For example:
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1234
<!DOCTYPE html>
<html>
<head>
<title>Example Website</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html> -
The response includes a status code (e.g., 200 OK), headers (e.g.,
Content-Type
), and the content of the requested resource (e.g., HTML).
-
-
Browser Rendering:
- The browser receives the HTTP/HTTPS response and starts rendering the web page.
- It parses the HTML, CSS, and JavaScript code.
- It fetches any additional resources (e.g., images, stylesheets, scripts) specified in the HTML.
- It executes the JavaScript code, which may modify the DOM (Document Object Model) and make further requests to the server.
- Finally, the browser displays the rendered web page to you.
-
Connection Closure (Optional):
- After the response has been sent, the TCP connection may be closed.
- In HTTP/1.1, the connection may be kept alive for subsequent requests (persistent connection).
- In HTTP/2 and HTTP/3, connections are typically persistent and multiplexed.
- The connection can be closed by either the client or the server, using a four-way handshake (FIN, ACK, FIN, ACK).