\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{woshiamiaojiang} \pdfinfo{ /Title (bytebytego-youtube.pdf) /Creator (Cheatography) /Author (woshiamiaojiang) /Subject (ByteByteGo - Youtube Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{ByteByteGo - Youtube Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{woshiamiaojiang} via \textcolor{DarkBackground}{\uline{cheatography.com/193748/cs/40330/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}woshiamiaojiang \\ \uline{cheatography.com/woshiamiaojiang} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 18th September, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{4} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Kafka is fast}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{1. Batch Processing: Kafka groups messages together into batches, which reduces the network calls and disk I/O operations, thereby increasing throughput. \newline % Row Count 4 (+ 4) 2. Sequential I/O: Kafka stores messages in a sequential, ordered manner on disk. This takes advantage of the underlying file system and disk's fast sequential read and write capabilities. \newline % Row Count 8 (+ 4) 3. Zero Copy: Kafka uses the zero-copy technique to transfer data directly from the file system cache to network buffers, which reduces CPU usage. \newline % Row Count 11 (+ 3) 4. Distributed System: Kafka is a distributed system that can be scaled horizontally by adding more nodes to the cluster. This allows it to handle high volumes of data and traffic. \newline % Row Count 15 (+ 4) 5. Immutable Messages: Once written, messages in Kafka are immutable and are not updated, which simplifies the system and improves performance. \newline % Row Count 18 (+ 3) 6. In-Memory Offsets: Kafka stores the offsets of messages in memory, which makes reading messages very fast.% Row Count 21 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{System Design Interview: A Step-By-Step Guide}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694957501_img1694957337764.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{CI/CD In 5 Minutes}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694957883_img1694957337971.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Cache Systems Every Developer Should Know}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694958099_img1694957338035.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{type a URL into your browser}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694958478_img1694957338081.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{type a URL into your browser?}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{1. URL Parsing: The browser parses the URL to extract the protocol (e.g., HTTP, HTTPS), domain name (e.g., www.example.com), and any additional path or query parameters. \newline % Row Count 4 (+ 4) 2. DNS Lookup: The browser checks its cache to find the IP address associated with the domain name. If not found, it sends a DNS (Domain Name System) lookup request to a DNS server to obtain the IP address. \newline % Row Count 9 (+ 5) 3. TCP Connection: The browser establishes a TCP (Transmission Control Protocol) connection with the web server at the obtained IP address. This involves a three-way handshake to establish a reliable connection. \newline % Row Count 14 (+ 5) 4. HTTP Request: The browser sends an HTTP (Hypertext Transfer Protocol) request to the web server. The request includes the HTTP method (e.g., GET, POST), the requested resource (e.g., /index.html), headers (e.g., user-agent, cookies), and other optional data. \newline % Row Count 20 (+ 6) 5. Server Processing: The web server receives the HTTP request and processes it. This may involve accessing databases, executing server-side code, or retrieving files from the server's file system. \newline % Row Count 24 (+ 4) 6. HTTP Response: The web server generates an HTTP response containing the requested resource, along with headers and a status code. The response may also include cookies, caching directives, or other metadata. \newline % Row Count 29 (+ 5) 7. Data Transfer: The server sends the HTTP response back to the browser over the established TCP connection. The response is divided into packets and transmitted over the network. \newline % Row Count 33 (+ 4) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{type a URL into your browser? (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{8. Browser Rendering: The browser receives the response and begins rendering the web page. It parses the HTML, executes any embedded scripts, and fetches additional resources like CSS stylesheets, images, or JavaScript files referenced in the HTML. \newline % Row Count 5 (+ 5) 9. Page Display: The browser combines the received resources to render and display the web page to the user. This includes rendering text, applying styles, and executing JavaScript code to add interactivity.% Row Count 10 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Top 5 Kafka use cases}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694961160_Snipaste_2023-09-17_22-32-24.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Database Types}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694961909_Snipaste_2023-09-17_22-44-55.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{type of different databases}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694962432_Snipaste_2023-09-17_22-44-55.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{HTTP/1.1, HTTP/2, and HTTP/3}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694963186_Snipaste_2023-09-17_23-06-09.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{5 Inter-Process Communications}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694963630_Snipaste_2023-09-17_23-13-32.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{The Code Review Pyramid}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694964044_Snipaste_2023-09-17_23-20-08.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Linux file system explained}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694964554_Snipaste_2023-09-17_23-28-57.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How GraphQL Works in Linkedln?}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694965708_Snipaste_2023-09-17_23-48-12.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Things to consider when using cache}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{\seqsplit{𝐒𝐮𝐢𝐭𝐚𝐛𝐥𝐞} \seqsplit{𝐒𝐜𝐞𝐧𝐚𝐫𝐢𝐨𝐬:} \newline % Row Count 2 (+ 2) - In-memory solution \newline % Row Count 3 (+ 1) - Read heavy system \newline % Row Count 4 (+ 1) - Data is not frequently updated \newline % Row Count 5 (+ 1) \seqsplit{𝐂𝐚𝐜𝐡𝐢𝐧𝐠} \seqsplit{𝐓𝐞𝐜𝐡𝐧𝐢𝐪𝐮𝐞𝐬:} \newline % Row Count 7 (+ 2) - Cache aside \newline % Row Count 8 (+ 1) - Write-through \newline % Row Count 9 (+ 1) - Read-through \newline % Row Count 10 (+ 1) - Write-around \newline % Row Count 11 (+ 1) - Write-back \newline % Row Count 12 (+ 1) 𝐂𝐚𝐜𝐡𝐞 \seqsplit{𝐄𝐯𝐢𝐜𝐭𝐢𝐨𝐧} \seqsplit{𝐀𝐥𝐠𝐨𝐫𝐢𝐭𝐡𝐦𝐬:} \newline % Row Count 14 (+ 2) - Least Recently Used (LRU) \newline % Row Count 15 (+ 1) - Least Frequently Used (LFU) \newline % Row Count 16 (+ 1) - First-in First-out (FIFO) \newline % Row Count 17 (+ 1) - Random Replacement (RR) \newline % Row Count 18 (+ 1) 𝐊𝐞𝐲 \seqsplit{𝐌𝐞𝐭𝐫𝐢𝐜𝐬:} \newline % Row Count 19 (+ 1) - Cache Hit Ratio \newline % Row Count 20 (+ 1) - Latency \newline % Row Count 21 (+ 1) - Throughput \newline % Row Count 22 (+ 1) - Invalidation Rate \newline % Row Count 23 (+ 1) - Memory Usage \newline % Row Count 24 (+ 1) - CPU usage \newline % Row Count 25 (+ 1) - Network usage \newline % Row Count 26 (+ 1) 𝐎𝐭𝐡𝐞𝐫 \seqsplit{𝐢𝐬𝐬𝐮𝐞𝐬:} \newline % Row Count 27 (+ 1) - Thunder herd on cold start \newline % Row Count 28 (+ 1) - Time-to-live (TTL)% Row Count 29 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Process and Thread}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694970352_Snipaste_2023-09-18_01-05-20.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{which type of database to use}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694970452_Snipaste_2023-09-18_01-07-18.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Online Ticketing Platform}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{The China Train tickets booking system has similar challenges as the Ticketmaster system: \newline % Row Count 2 (+ 2) Very high concurrent visits during peak hours. \newline % Row Count 3 (+ 1) The QPS for checking remaining tickets and orders is very high \newline % Row Count 5 (+ 2) A lot of bots \newline % Row Count 6 (+ 1) The solutions \newline % Row Count 7 (+ 1) Separate read and write requests. Because anxious users kept refreshing the web page to check if there were tickets available, the system could under huge pressure. \newline % Row Count 11 (+ 4) To handle the calculation and query in memory, the remaining ticket components were moved entirely to GemFire. It is possible to fit the entire country's train tickets into several Gigabytes of memory. \newline % Row Count 16 (+ 5) In addition, the order query component was moved to GemFire to reduce the load on the order database. Hadoop was used to store historical orders. \newline % Row Count 19 (+ 3) Leverage public cloud for elastic capacity. \newline % Row Count 20 (+ 1) Ban bots. It reduced the traffic by 95\%. \newline % Row Count 21 (+ 1) Increase the bandwidth of the system. \newline % Row Count 22 (+ 1) Increase system availability by setting up more data centers in different cities. \newline % Row Count 24 (+ 2) Design multiple emergency plans.% Row Count 25 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How will you design the Stack Overflow website?}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{What people think it should look like \newline % Row Count 1 (+ 1) The interviewer is probably expecting something on the left side. \newline % Row Count 3 (+ 2) Microservice is used to decompose the system into small components. \newline % Row Count 5 (+ 2) Each service has its own database. Use cache heavily. \newline % Row Count 7 (+ 2) The service is sharded. \newline % Row Count 8 (+ 1) The services talk to each other asynchronously through message queues. \newline % Row Count 10 (+ 2) The service is implemented using Event Sourcing with CQRS. \newline % Row Count 12 (+ 2) Showing off knowledge in distributed systems such as eventual consistency, CAP theorem, etc. \newline % Row Count 14 (+ 2) What it actually is \newline % Row Count 15 (+ 1) Stack Overflow serves all the traffic with only 9 on-premise web servers, and it's on monolith! It has its own servers and does not run on the cloud.% Row Count 19 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Secret Sauce Behind NoSQL: LSM Tree}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694972380_Snipaste_2023-09-18_01-39-21.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Is HTTPs safe?}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694973246_Snipaste_2023-09-18_01-53-54.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Design patterns cheat sheet}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694973730_4371b692-437f-4b0f-ad92-3c8ee578b75a_1252x1606.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Design patterns cheat sheet2}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694973784_Snipaste_2023-09-18_02-02-31.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{API Platform Landscape}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694974338_4d42be54-deb2-48c3-96f1-e8d33ebd2184_8008x7448.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{scan pay}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Here are the steps for generating the QR code: \newline % Row Count 1 (+ 1) When you want to pay for your shopping, the cashier tallies up all the goods and calculates the total amount due, for example, \$123.45. The checkout has an order ID of SN129803. The cashier clicks the "checkout" button. \newline % Row Count 6 (+ 5) The cashier's computer sends the order ID and the amount to PSP. \newline % Row Count 8 (+ 2) The PSP saves this information to the database and generates a QR code URL. \newline % Row Count 10 (+ 2) PSP's Payment Gateway service reads the QR code URL. \newline % Row Count 12 (+ 2) The payment gateway returns the QR code URL to the merchant's computer. \newline % Row Count 14 (+ 2) The merchant's computer sends the QR code URL (or image) to the checkout counter. \newline % Row Count 16 (+ 2) The checkout counter displays the QR code. \newline % Row Count 17 (+ 1) These 7 steps are completed in less than a second. Now it's the consumer's turn to pay from their digital wallet by scanning the QR code: \newline % Row Count 20 (+ 3) The consumer opens their digital wallet app to scan the QR code. \newline % Row Count 22 (+ 2) After confirming the amount is correct, the client clicks the "pay" button. \newline % Row Count 24 (+ 2) The digital wallet App notifies the PSP that the consumer has paid the given QR code. \newline % Row Count 26 (+ 2) The PSP payment gateway marks this QR code as paid and returns a success message to the consumer's digital wallet App. \newline % Row Count 29 (+ 3) The PSP payment gateway notifies the merchant that the consumer has paid the given QR code. \newline % Row Count 31 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{scan pay (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Over to you: I have detailed how to pay using a dynamic QR code. It is dynamic because the QR code is dynamically generated each time. But sometimes, you could pay by scanning a printed QR code in a merchant's shop, which is called the static QR code. Do you know how a static QR code works?% Row Count 6 (+ 6) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Linux file permission illustrated.}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694975359_Snipaste_2023-09-18_02-29-05.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How to store passwords safely}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694975645_Snipaste_2023-09-18_02-33-53.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{avoid crawling duplicate URLs at Google scale}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Option 1: Use a Set data structure to check if a URL already exists or not. Set is fast, but it is not space-efficient. \newline % Row Count 3 (+ 3) Option 2: Store URLs in a database and check if a new URL is in the database. This can work but the load to the database will be very high. \newline % Row Count 6 (+ 3) Option 3: 𝐁𝐥𝐨𝐨𝐦 \seqsplit{𝐟𝐢𝐥𝐭𝐞𝐫.} This option is preferred. Bloom filter was proposed by Burton Howard Bloom in 1970. It is a probabilistic data structure, that is used to test whether an element is a member of a set. \newline % Row Count 11 (+ 5) 🔹 false: the element is definitely not in the set. \newline % Row Count 13 (+ 2) 🔹 true: the element is probably in the set. \newline % Row Count 14 (+ 1) False-positive matches are possible, but false negatives are not. \newline % Row Count 16 (+ 2) The diagram below illustrates how the Bloom filter works. The basic data structure for the Bloom filter is Bit Vector. Each bit represents a hashed value.% Row Count 20 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{scale a website to support millions of users}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Step 1 - With the growth of the user base, one single application server cannot handle the traffic anymore. We put the application server and the database server into two separate servers. \newline % Row Count 4 (+ 4) Step 2 - The business continues to grow, and a single application server is no longer enough. So we deploy a cluster of application servers. \newline % Row Count 7 (+ 3) Step 3 - Now the incoming requests have to be routed to multiple application servers, how can we ensure each application server gets an even load? The load balancer handles this nicely. \newline % Row Count 11 (+ 4) Step 4 - With the business continuing to grow, the database might become the bottleneck. To mitigate this, we separate reads and writes in a way that frequent read queries go to read replicas. With this setup, the throughput for the database writes can be greatly increased. \newline % Row Count 17 (+ 6) Step 5 - Suppose the business continues to grow. One single database cannot handle the load on both the inventory table and user table. We have a few options: \newline % Row Count 21 (+ 4) 1. Vertical scaling. Adding more power (CPU, RAM, etc.) to the database server. It has a hard limit. \newline % Row Count 24 (+ 3) 2. Horizontal scaling by adding more database servers. \newline % Row Count 26 (+ 2) 3. Adding a caching layer to offload read requests. \newline % Row Count 28 (+ 2) Step 6 - Now we can modularize the functions into different services. The architecture becomes service-oriented / microservice.% Row Count 31 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{S3-like storage system}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{In S3, an object resides in a bucket. The path looks like this: \seqsplit{/bucket-to-share/script.txt.} The bucket only has metadata. The object has metadata and the actual data. \newline % Row Count 4 (+ 4) The diagram below (Figure 2) illustrates how file uploading works. In this example, we first create a bucket named "bucket-to-share" and then upload a file named "script.txt" to the bucket. \newline % Row Count 8 (+ 4) 1. The client sends an HTTP PUT request to create a bucket named "bucket-to-share." The request is forwarded to the API service. \newline % Row Count 11 (+ 3) 2. The API service calls Identity and Access Management (IAM) to ensure the user is authorized and has WRITE permission. \newline % Row Count 14 (+ 3) 3. The API service calls the metadata store to create an entry with the bucket info in the metadata database. Once the entry is created, a success message is returned to the client. \newline % Row Count 18 (+ 4) 4. After the bucket is created, the client sends an HTTP PUT request to create an object named "script.txt". \newline % Row Count 21 (+ 3) 5. The API service verifies the user's identity and ensures the user has WRITE permission on the bucket. \newline % Row Count 24 (+ 3) 6. Once validation succeeds, the API service sends the object data in the HTTP PUT payload to the data store. The data store persists the payload as an object and returns the UUID of the object. \newline % Row Count 28 (+ 4) 7. The API service calls the metadata store to create a new entry in the metadata database. It contains important metadata such as the object\_id (UUID), bucket\_id (which bucket the object belongs to), object\_name, etc.% Row Count 33 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Match buy and sell stock orders}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Stocks go up and down. Do you know what data structure is used to efficiently match buy and sell orders? \newline % Row Count 3 (+ 3) Stock exchanges use order books. An order book is an electronic list of buy and sell orders, organized by price levels. It has a buy book and a sell book, where each side of the book contains a bunch of price levels, and each price level contains a list of orders (first in first out). \newline % Row Count 9 (+ 6) The diagram below is an example of price levels and the queued quantity at each price level. \newline % Row Count 11 (+ 2) So what happens when you place a market order to buy 2700 shares in the diagram? \newline % Row Count 13 (+ 2) - The buy order is matched with all the sell orders at price 100.10, and the first order at price 100.11 (illustrated in light red). \newline % Row Count 16 (+ 3) - Now because of the big buy order which "eats up" the first price level on the sell book, the best ask price goes up from 100.10 to 100.11. \newline % Row Count 19 (+ 3) - So when the market is bullish, people tend to buy stocks aggressively, and the price goes up and up. \newline % Row Count 22 (+ 3) An efficient data structure for an order book must satisfy: \newline % Row Count 24 (+ 2) - Constant lookup time. Operations include: get volume at a price level or between price levels, query best bid/ask. \newline % Row Count 27 (+ 3) - Fast \seqsplit{add/cancel/execute/update} operations, preferably O(1) time complexity. Operations include: place a new order, cancel an order, and match an order.% Row Count 31 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Why is single-threaded Redis so fast?}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{1 in-memory database \newline % Row Count 1 (+ 1) 2 io multiplexing a single thread to wait on many sockets \newline % Row Count 3 (+ 2) 3 efficient data structure% Row Count 4 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Top 5 Redis Use Cases}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694956462_img1694664826606.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Top 5 Most Used Architecture Patterns}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694956689_img1694664826632.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Algorithms You Should Know}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694957601_img1694957337853.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Top 7 Ways to 10x Your API Performance}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694957731_img1694957337893.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Git MERGE vs REBASE: Everything You Need to Know}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694958183_img1694957338077.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{SSL, TLS, HTTPS Explained}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694958417_img1694957338091.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{SSL, TLS, HTTPS Explained}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{1. Client Hello: The client initiates a secure connection by sending a "Client Hello" message to the server. This message includes information about the client's supported encryption algorithms and other parameters. \newline % Row Count 5 (+ 5) 2. Server Hello: The server responds with a "Server Hello" message, selecting the strongest encryption algorithm and other parameters that both the client and server support. \newline % Row Count 9 (+ 4) 3. Certificate Exchange: The server sends its digital certificate to the client. The certificate contains the server's public key, which is used for encryption and authentication. \newline % Row Count 13 (+ 4) 4. Certificate Validation: The client verifies the authenticity of the server's certificate. It checks if the certificate is issued by a trusted Certificate Authority (CA) and if it has not expired or been revoked. \newline % Row Count 18 (+ 5) 5. Key Exchange: The client generates a random symmetric encryption key and encrypts it using the server's public key. This encrypted key is sent to the server. \newline % Row Count 22 (+ 4) 6. Session Key: The server decrypts the encrypted key using its private key and obtains the symmetric encryption key. Both the client and server now have the same session key for secure communication. \newline % Row Count 27 (+ 5) 7. Secure Communication: The client and server use the session key to encrypt and decrypt data exchanged between them. This ensures that the data transmitted over the network is protected from eavesdropping and tampering. \newline % Row Count 32 (+ 5) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{SSL, TLS, HTTPS Explained (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{8. HTTPS Connection: From this point onwards, the client and server communicate using the secure HTTPS protocol. All HTTP requests and responses are encrypted and decrypted using the session key.% Row Count 4 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{What is API Gateway?}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694958887_img1694957338103.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How to Choose a Replication Strategy}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{1.leader-follower model \newline % Row Count 1 (+ 1) 2.multi-leader \newline % Row Count 2 (+ 1) Multi-leader replication provides high availability but requires careful design around consensus, conflict detection, and resolution mechanisms. \newline % Row Count 5 (+ 3) The primary advantage of this model is increased write availability \newline % Row Count 7 (+ 2) disadvantage: Managing Conflict: \newline % Row Count 8 (+ 1) 2.1Last Write Wins \newline % Row Count 9 (+ 1) 2.2Conflict-free Replicated Data Types (CRDTs) \newline % Row Count 10 (+ 1) CRDTs allow for seamless reconciliation of conflicting changes by merging them. \newline % Row Count 12 (+ 2) 2.3Operational Transformation \newline % Row Count 13 (+ 1) Operational transformation is often used in real-time collaborative applications. It takes the operation itself into account, not just the state of the data. \newline % Row Count 17 (+ 4) 2.4Application-specific Resolution \newline % Row Count 18 (+ 1) 3.leaderless replication \newline % Row Count 19 (+ 1) Quorum Writes and Reads \newline % Row Count 20 (+ 1) In this system, we use three important values. \newline % Row Count 21 (+ 1) 'n' is the total number of nodes in our system. \newline % Row Count 22 (+ 1) 'W', the write quorum, is the minimum number of nodes that need to agree for a write to be considered successful. \newline % Row Count 25 (+ 3) 'r', the read quorum, is the minimum number of nodes that need to agree for a read to be valid. \newline % Row Count 27 (+ 2) For strong consistency, a general guideline is to have w + r \textgreater{} n. It ensures that any read overlaps with any write and returns the most recent value.% Row Count 30 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{HTTPS, SSL Handshake, and Data Encryption}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694962720_7719f68a-5acb-4cb3-a7aa-5fd6af20a6d8_1280x1832.jpg}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{CI/CD Pipeline Explained in Simple Terms}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694962853_Snipaste_2023-09-17_22-59-59.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{HTTP verbs}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694965268_Snipaste_2023-09-17_23-36-06.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Status Codes}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694965317_Snipaste_2023-09-17_23-41-43.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{SQL Execution Order}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694965502_Snipaste_2023-09-17_23-44-27.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Common Rate Limiting Algorithms}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Fixed Window Counter \newline % Row Count 1 (+ 1) Sliding Window Log \newline % Row Count 2 (+ 1) Sliding Window Counter \newline % Row Count 3 (+ 1) Token Bucket \newline % Row Count 4 (+ 1) Leaky Bucket% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{db selection}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694966133_Snipaste_2023-09-17_23-55-08.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{8 Data Structures in Databases}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694969307_Snipaste_2023-09-18_00-48-14.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{2-factor authenticators}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694969599_Snipaste_2023-09-18_00-53-08.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How does REST API work?}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694970558_Snipaste_2023-09-18_01-09-05.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{OSI model}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694970941_Snipaste_2023-09-18_01-15-29.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{proxy}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{A forward proxy is a server that sits between a group of client machines and the internet. \newline % Row Count 2 (+ 2) A reverse proxy sits between the internet and the web servers. It intercepts the requests from clients and talks to the web server on behalf of the clients.% Row Count 6 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Twitter architecture}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694971410_Snipaste_2023-09-18_01-23-15.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{iQIYI database selection trees}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694971694_Snipaste_2023-09-18_01-27-56.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Five ways to generate distributed unique ID}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694972115_Snipaste_2023-09-18_01-34-57.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Why is RESTful API so popular?}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694973383_Snipaste_2023-09-18_01-56-09.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{What is a File Descriptor?}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{A file descriptor represents an open file. It is a unique number assigned by the operating system to each file. It is an abstraction for working with files. We need to use file descriptors to read from or write to files in our program. Each process maintains its own file descriptor table. \newline % Row Count 6 (+ 6) The diagram below shows the layered architecture in Linux filesystem. Let's take process 1234 as an example. \newline % Row Count 9 (+ 3) 🔹 In User Space \newline % Row Count 10 (+ 1) When we open a file called "fileA.txt" in Process 1234, we get file descriptor fd1, which is equal to 3. We can then pass the file descriptor to other functions to write data to the file. \newline % Row Count 14 (+ 4) 🔹 In Kernel Space \newline % Row Count 15 (+ 1) In Linux kernel, there is a process table to maintain the data for the processes. Each process has an entry in the table. Each process maintains a file descriptor table, with file descriptors as its indices. Notice that file descriptors 0,1 and 2 are reserved in each file descriptor table to represent stdin, stdout, and stderr. \newline % Row Count 22 (+ 7) The file pointer points to an entry in the open file table, which has information about open files across all processes. Multiple file descriptors can point to the same file table entry. For example, file descriptor 0, 1 and 2 points to the same open file table entry. \newline % Row Count 28 (+ 6) Since different open file table entries can represent the same file, it is a waste of resources to store the file static information so many times. We need another abstraction layer called 'vnode table' to store the static data. \newline % Row Count 33 (+ 5) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{What is a File Descriptor? (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{In each file table entry, there is a vnode pointer, which points to an entry in vnode table. The static information includes file type, function pointers, reference counts, inode etc. inode describes a physical object in the filesystem. \newline % Row Count 5 (+ 5) 🔹 In Filesystem \newline % Row Count 6 (+ 1) The inode array element stores the actual file information, including permission mode, owners, timestamps, etc. inode also points to the data blocks stored in the filesystem. \newline % Row Count 10 (+ 4) Over to you: When we close a file in a program, do you know which entries are deleted in these data structures?% Row Count 13 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Flash sale system}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694974481_Snipaste_2023-09-18_02-14-26.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{notifications pushed to our phones or PCs}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694974663_Snipaste_2023-09-18_02-17-30.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How do we design for high availability}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694975002_Snipaste_2023-09-18_02-22-58.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Inner, Left, Right, and Full join}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694975153_Snipaste_2023-09-18_02-25-35.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Process and Thread}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{A Process means a program is in execution. When a program is loaded into the memory and becomes active, the program becomes a process. The process requires some essential resources such as registers, program counter, and stack. \newline % Row Count 5 (+ 5) A Thread is the smallest unit of execution within a process. \newline % Row Count 7 (+ 2) The following process explains the relationship between program, process, and thread. \newline % Row Count 9 (+ 2) 1. The program contains a set of instructions. \newline % Row Count 10 (+ 1) 2. The program is loaded into memory. It becomes one or more running processes. \newline % Row Count 12 (+ 2) 3. When a process starts, it is assigned memory and resources. A process can have one or more threads. For example, in the Microsoft Word app, a thread might be responsible for spelling checking and the other thread for inserting text into the doc. \newline % Row Count 17 (+ 5) Main differences between process and thread: \newline % Row Count 18 (+ 1) 🔹 Processes are usually independent, while threads exist as subsets of a process. \newline % Row Count 20 (+ 2) 🔹 Each process has its own memory space. Threads that belong to the same process share the same memory. \newline % Row Count 23 (+ 3) 🔹 A process is a heavyweight operation. It takes more time to create and terminate. \newline % Row Count 25 (+ 2) 🔹 Context switching is more expensive between processes. \newline % Row Count 27 (+ 2) 🔹 Inter-thread communication is faster for threads.% Row Count 29 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Redis vs Memcached}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694976439_7591f8fc-5855-4821-90dc-ede7deb7339a_3342x2310.jpg}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Worldwide Interbank Financial Telecommunication}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Step 1: Bank A sends a message with transfer details to Regional Processor A in New York. The destination is Bank B. \newline % Row Count 3 (+ 3) Step 2: Regional processor validates the format and sends it to Slice Processor A. The Regional Processor is responsible for input message validation and output message queuing. The Slice Processor is responsible for storing and routing messages safely. \newline % Row Count 9 (+ 6) Step 3: Slice Processor A stores the message. \newline % Row Count 10 (+ 1) Step 4: Slice Processor A informs Regional Processor A the message is stored. \newline % Row Count 12 (+ 2) Step 5: Regional Processor A sends ACK/NAK to Bank A. ACK means a message will be sent to Bank B. NAK means the message will NOT be sent to Bank B. \newline % Row Count 15 (+ 3) Step 6: Slice Processor A sends the message to Regional Processor B in London. \newline % Row Count 17 (+ 2) Step 7: Regional Processor B stores the message temporarily. \newline % Row Count 19 (+ 2) Step 8: Regional Processor B assigns a unique ID MON (Message Output Number) to the message and sends it to Slice Processor B \newline % Row Count 22 (+ 3) Step 9: Slice Processor B validates MON. \newline % Row Count 23 (+ 1) Step 10: Slice Processor B authorizes Regional Processor B to send the message to Bank B. \newline % Row Count 25 (+ 2) Step 11: Regional Processor B sends the message to Bank B. \newline % Row Count 27 (+ 2) Step 12: Bank B receives the message and stores it. \newline % Row Count 29 (+ 2) Step 13: Bank B sends UAK/UNK to Regional Processor B. UAK (user positive acknowledgment) means Bank B received the message without error; UNK (user negative acknowledgment) means Bank B received checksum failure. \newline % Row Count 34 (+ 5) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Worldwide Interbank Financial Telecommunication (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Step 14: Regional Processor B creates a report based on Bank B's response, and sends it to Slice Processor B. \newline % Row Count 3 (+ 3) Step 15: Slice Processor B stores the report. \newline % Row Count 4 (+ 1) Step 16 - 17: Slice Processor B sends a copy of the report to Slice Processor A. Slice Processor A stores the report.% Row Count 7 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Low latency stock exchange}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{How does a modern stock exchange achieve microsecond latency? The principal is: \newline % Row Count 2 (+ 2) Do less on the critical path \newline % Row Count 3 (+ 1) - Fewer tasks on the critical path \newline % Row Count 4 (+ 1) - Less time on each task \newline % Row Count 5 (+ 1) - Fewer network hops \newline % Row Count 6 (+ 1) - Less disk usage \newline % Row Count 7 (+ 1) For the stock exchange, the critical path is: \newline % Row Count 8 (+ 1) - start: an order comes into the order manager \newline % Row Count 9 (+ 1) - mandatory risk checks \newline % Row Count 10 (+ 1) - the order gets matched and the execution is sent back \newline % Row Count 12 (+ 2) - end: the execution comes out of the order manager \newline % Row Count 14 (+ 2) Other non-critical tasks should be removed from the critical path. \newline % Row Count 16 (+ 2) We put together a design as shown in the diagram: \newline % Row Count 17 (+ 1) - deploy all the components in a single giant server (no containers) \newline % Row Count 19 (+ 2) - use shared memory as an event bus to communicate among the components, no hard disk \newline % Row Count 21 (+ 2) - key components like Order Manager and Matching Engine are single-threaded on the critical path, and each pinned to a CPU so that there is no context switch and no locks \newline % Row Count 25 (+ 4) - the single-threaded application loop executes tasks one by one in sequence \newline % Row Count 27 (+ 2) - other components listen on the event bus and react accordingly% Row Count 29 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Load Balance Algorithms}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694957089_img1694664826539.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Top 5 Most-Used Deployment Strategies}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694957777_img1694957337941.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Secret To Optimizing SQL Queries}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{To write sargable queries: \newline % Row Count 1 (+ 1) · Avoid using functions or calculations on indexed columns in the WHERE clause \newline % Row Count 3 (+ 2) · Use direct comparisons when possible, instead of wrapping the column in a function \newline % Row Count 5 (+ 2) · If we need to use a function on a column, consider creating a computed column or a function-based index, if the database system supports it% Row Count 8 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{10 Key Data Structures We Use Every Day}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694958044_img1694957337996.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{What Are Microservices Really All About?}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694958986_img1694957338111.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Bare Metal, Virtual Machines, and Containers}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694959400_1694959356756.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{\seqsplit{如何设计一个高并发系统}?}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{1. \seqsplit{运用自动扩缩容,监控和报警} \newline % Row Count 1 (+ 1) 2. \seqsplit{扩展微服务架构,根据具体服务的需求进行独立扩展} \newline % Row Count 3 (+ 2) 3. 优化缓存策略 \newline % Row Count 4 (+ 1) 4. 确保负载均衡 \newline % Row Count 5 (+ 1) 5. \seqsplit{冗余和故障转移,数据中心故障} \newline % Row Count 6 (+ 1) 1. \seqsplit{水平扩展(Horizontal} \seqsplit{Scaling):通过增加服务器实例来分散负载,使系统能够处理更多的并发请求。这可以通过负载均衡器来实现,将请求分发到多个服务器上。} \newline % Row Count 11 (+ 5) 2. \seqsplit{多级缓存(Caching):使用缓存来存储频繁访问的数据,减少对后端数据库或其他资源的访问次数。常见的缓存技术包括内存缓存(如Redis)和分布式缓存(如Memcached)。} \newline % Row Count 16 (+ 5) 3. \seqsplit{异步处理(Asynchronous} \seqsplit{Processing):将耗时的操作转化为异步任务,通过消息队列或任务队列来处理。这样可以减少请求的等待时间,提高系统的吞吐量。} \newline % Row Count 21 (+ 5) 4. \seqsplit{数据库优化:使用合适的数据库引擎和优化技术,如索引、分区、缓存查询结果等,以提高数据库的读写性能和并发处理能力。} \newline % Row Count 25 (+ 4) 5. \seqsplit{无状态设计(Stateless} \seqsplit{Design):尽量设计无状态的系统,将状态信息存储在外部,如数据库或缓存中。这样可以使系统更容易水平扩展,并提高系统的可伸缩性。} \newline % Row Count 30 (+ 5) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{\seqsplit{如何设计一个高并发系统}? (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{6. 限流和熔断(Rate Limiting and Circuit \seqsplit{Breaking):通过限制请求的速率或在系统负载过高时断开部分请求,以保护系统免受过载的影响。} \newline % Row Count 4 (+ 4) 7. \seqsplit{分布式架构(Distributed} \seqsplit{Architecture):将系统拆分为多个独立的服务,通过消息传递或API调用进行通信。这样可以提高系统的可扩展性和容错性。} \newline % Row Count 8 (+ 4) 8. \seqsplit{监控和自动化:建立监控系统来实时监测系统的性能和健康状况,及时发现并解决潜在的问题。自动化部署和扩展可以减少人工干预,提高系统的可靠性和可维护性。} \newline % Row Count 13 (+ 5) 9. 容错和恢复(Fault Tolerance and \seqsplit{Recovery):设计系统以容忍部分组件或服务的故障,并能够快速恢复。使用备份和冗余机制来保证系统的可用性。} \newline % Row Count 17 (+ 4) 10. \seqsplit{性能测试和优化:进行系统的性能测试和基准测试,找出瓶颈和性能瓶颈,并进行相应的优化和调整。}% Row Count 20 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Top 5 Caching Strategies}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694960446_f8210268-53f6-4d7f-a822-863c293505f5_2880x3340.jpg}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{There are 3 ways to use Redis as a message queue}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694960704_Snipaste_2023-09-17_22-24-44.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{There are 3 ways to use Redis as a message queue}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Pub/Sub is convenient but has some delivery restrictions. The consumer subscribes to a key and receives the data when a producer publishes data to the same key. The restriction is that the data is delivered at most once. If a consumer was down and didn't receive the published data, that data is lost. Also, the data is not persisted on disk. If Redis goes down, all Pub/Sub data is lost. Pub/Sub is suitable for metrics monitoring where some data loss is acceptable. \newline % Row Count 10 (+ 10) The List data structure in Redis can construct a FIFO (First-In-First-Out) queue. The consumer uses BLPOP to wait for messages in blocking mode, so a timeout should be applied. Consumers waiting on the same List form a consumer group where each message is consumed by only one consumer. As a Redis data structure, List can be persisted to disk. \newline % Row Count 17 (+ 7) Stream solves the restrictions of the above two methods. Consumers choose where to read messages from - "\$" for new messages, "\textless{}id\textgreater{}" for a specific message id, or "0-0" for reading from the start.% Row Count 22 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Benefits of Message Queues}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Fan-out \newline % Row Count 1 (+ 1) Asynchronous Processing \newline % Row Count 2 (+ 1) Rate Limiting \newline % Row Count 3 (+ 1) Decoupling \newline % Row Count 4 (+ 1) Horizontal Scalability \newline % Row Count 5 (+ 1) Message Persistence \newline % Row Count 6 (+ 1) Batch Processing \newline % Row Count 7 (+ 1) Message Ordering% Row Count 8 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{A comparison between B-Tree vs B+ Tree}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694963296_Snipaste_2023-09-17_23-08-01.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{9 best practices for developing microservices}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694963931_Snipaste_2023-09-17_23-18-30.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{data warehouse and a data lake}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694964250_Snipaste_2023-09-17_23-23-55.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{The 10 Algorithms That Dominate Our World}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694965564_Snipaste_2023-09-17_23-45-49.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{18 Most-used Linux Commands You Should Know}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694966047_Snipaste_2023-09-17_23-53-50.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Buy Now, Pay Later}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694969373_Snipaste_2023-09-18_00-49-20.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{microservices tech stack}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694969877_Snipaste_2023-09-18_00-57-40.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{user identity management}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{WWW-Authenticate is the most basic method. You are asked for the username and password by the browser. As a result of the inability to control the login life cycle, it is seldom used today. \newline % Row Count 4 (+ 4) A finer control over the login life cycle is session-cookie. The server maintains session storage, and the browser keeps the ID of the session. A cookie usually only works with browsers and is not mobile app friendly. \newline % Row Count 9 (+ 5) To address the compatibility issue, the token can be used. The client sends the token to the server, and the server validates the token. The downside is that the token needs to be encrypted and decrypted, which may be time-consuming. \newline % Row Count 14 (+ 5) JWT is a standard way of representing tokens. This information can be verified and trusted because it is digitally signed. Since JWT contains the signature, there is no need to save session information on the server side. \newline % Row Count 19 (+ 5) By using SSO (single sign-on), you can sign on only once and log in to multiple websites. It uses CAS (central authentication service) to maintain cross-site information \newline % Row Count 23 (+ 4) By using OAuth 2.0, you can authorize one website to access your information on another website% Row Count 25 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{B-Tree vs. LSM-Tree}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{B-Tree \newline % Row Count 1 (+ 1) B-Tree is the most widely used indexing data structure in almost all relational databases. \newline % Row Count 3 (+ 2) The basic unit of information storage in B-Tree is usually called a "page". Looking up a key traces down the range of keys until the actual value is found. \newline % Row Count 7 (+ 4) LSM-Tree \newline % Row Count 8 (+ 1) LSM-Tree (Log-Structured Merge Tree) is widely used by many NoSQL databases, such as Cassandra, LevelDB, and RocksDB. \newline % Row Count 11 (+ 3) LSM-trees maintain key-value pairs and are persisted to disk using a Sorted Strings Table (SSTable), in which the keys are sorted. \newline % Row Count 14 (+ 3) Level 0 segments are periodically merged into Level 1 segments. This process is called compaction. \newline % Row Count 16 (+ 2) The biggest difference is probably this: \newline % Row Count 17 (+ 1) B-Tree enables faster reads \newline % Row Count 18 (+ 1) LSM-Tree enables fast writes% Row Count 19 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Resiliency Patterns}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694971936_Snipaste_2023-09-18_01-32-03.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{What is GraphQL}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694972185_Snipaste_2023-09-18_01-36-08.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How is SQL executed?}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694973533_Snipaste_2023-09-18_01-58-30.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{scan to pay}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694974032_Snipaste_2023-09-18_02-06-56.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Designing a location-based service}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694974148_Snipaste_2023-09-18_02-08-52.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{how to make your website rank higher?}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{A search engine works in 3 stages: \newline % Row Count 1 (+ 1) The crawler reads the page content (HTML code) and follows the hyperlink to read more web pages. \newline % Row Count 3 (+ 2) The preprocessor also works in 3 steps: \newline % Row Count 4 (+ 1) It removes HTML tags and 'Stop' words, which are words like 'a' or 'an' or 'the.' It also removes other noise that is not relevant to the web page's content, for example, the disclaimer. \newline % Row Count 9 (+ 5) Then the keywords form structured indices, called forward indices and inverted indices. \newline % Row Count 11 (+ 2) The preprocessor calculates the hyperlink relationships, for example, how many hyperlinks are on the web page and how many hyperlinks point to it. \newline % Row Count 14 (+ 3) When a user types in a search term, the search engine uses the indices and ranking algorithms to rank the web pages and presents the search results to the user. \newline % Row Count 18 (+ 4) How do we make our website rank higher in search results? The diagram below shows some ways to do this. \newline % Row Count 21 (+ 3) Optimize website structure: \newline % Row Count 22 (+ 1) We need to make it easier for the crawler to crawl our website. Remove anything the crawler cannot read, including flash, frames, and dynamic URLs. Make the website hierarchy less deep, so the web pages are less distant from the main home page. \newline % Row Count 27 (+ 5) The URLs must be short and descriptive. Try to include keywords in the URLs, as well. It will also help to use HTTPS. But don't use underscore in the URL because that will screw up the tokenization. \newline % Row Count 32 (+ 5) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{how to make your website rank higher? (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Choose the keywords to optimize for: \newline % Row Count 1 (+ 1) Keywords must be relevant to what the website is selling, and they must have business values. For example, a keyword is considered valuable if it's a popular search, but has fewer search results. \newline % Row Count 5 (+ 4) Optimize the web page \newline % Row Count 6 (+ 1) The crawler crawls the HTML contents. Therefore the title and description should be optimized to include keywords and be concise. The body of the web page should include relevant keywords. \newline % Row Count 10 (+ 4) Another aspect is the user experience. In May 2020, Google published Core Web Vitals, officially listing user experience as an important factor of page ranking algorithms. \newline % Row Count 14 (+ 4) External link \newline % Row Count 15 (+ 1) If our website is referenced by a highly-ranked website, it will increase our website's ranking. So carefully building external links is important. Publishing high-quality content on your website which is useful to other users, is a good way to attract external links. \newline % Row Count 21 (+ 6) Over to you: What are your top SEO recommendations?% Row Count 23 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Single Sign-On}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694975582_Snipaste_2023-09-18_02-32-48.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How to design a secure web API access}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Token based \newline % Row Count 1 (+ 1) Step 1 - the user enters their password into the client, and the client sends the password to the Authentication Server. \newline % Row Count 4 (+ 3) Step 2 - the Authentication Server authenticates the credentials and generates a token with an expiry time. \newline % Row Count 7 (+ 3) Steps 3 and 4 - now the client can send requests to access server resources with the token in the HTTP header. This access is valid until the token expires. \newline % Row Count 11 (+ 4) HMAC based \newline % Row Count 12 (+ 1) This mechanism generates a Message Authentication Code (signature) by using a hash function (SHA256 or MD5). \newline % Row Count 15 (+ 3) Steps 1 and 2 - the server generates two keys, one is Public APP ID (public key) and the other one is API Key (private key). \newline % Row Count 18 (+ 3) Step 3 - we now generate a HMAC signature on the client side (hmac A). This signature is generated with a set of attributes listed in the diagram. \newline % Row Count 21 (+ 3) Step 4 - the client sends requests to access server resources with hmac A in the HTTP header. \newline % Row Count 23 (+ 2) Step 5 - the server receives the request which contains the request data and the authentication header. It extracts the necessary attributes from the request and uses the API key that's stored on the server side to generate a signature (hmac B.) \newline % Row Count 28 (+ 5) Steps 6 and 7 - the server compares hmac A (generated on the client side) and hmac B (generated on the server side). If they are matched, the requested resource will be returned to the client. \newline % Row Count 32 (+ 4) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How to design a secure web API access (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Question - How does HMAC authentication ensure data integrity? Why do we include "request timestamp" in HMAC signature generation?% Row Count 3 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{top caching strategies?}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694976546_Snipaste_2023-09-18_02-48-49.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Vertical partitioning vs horizontal partitioning}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694976787_Snipaste_2023-09-18_02-52-52.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Proximity service}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{- Business Service \newline % Row Count 1 (+ 1) - Add/delete/update restaurant information \newline % Row Count 2 (+ 1) - Customers view restaurant details \newline % Row Count 3 (+ 1) - Location-based Service \newline % Row Count 4 (+ 1) - Given a radius and location, return a list of nearby restaurants \newline % Row Count 6 (+ 2) How are the restaurant locations stored in the database so that LBS can return nearby restaurants efficiently? \newline % Row Count 9 (+ 3) Store the latitude and longitude of restaurants in the database? The query will be very inefficient when you need to calculate the distance between you and every restaurant. \newline % Row Count 13 (+ 4) One way to speed up the search is using the geohash algorithm. \newline % Row Count 15 (+ 2) First, divide the planet into four quadrants along with the prime meridian and equator: \newline % Row Count 17 (+ 2) - Latitude range {[}-90, 0{]} is represented by 0 \newline % Row Count 18 (+ 1) - Latitude range {[}0, 90{]} is represented by 1 \newline % Row Count 19 (+ 1) - Longitude range {[}-180, 0{]} is represented by 0 \newline % Row Count 20 (+ 1) - Longitude range {[}0, 180{]} is represented by 1 \newline % Row Count 21 (+ 1) Second, divide each grid into four smaller grids. Each grid can be represented by alternating between longitude bit and latitude bit. \newline % Row Count 24 (+ 3) So when you want to search for the nearby restaurants in the red-highlighted grid, you can write SQL like: \newline % Row Count 27 (+ 3) SELECT * FROM geohash\_index WHERE geohash LIKE `01\%` \newline % Row Count 29 (+ 2) Geohash has some limitations. There can be a lot of restaurants in one grid (downtown New York), but none in another grid (ocean). So there are other more complicated algorithms to optimize the process. Let me know if you are interested in the details.% Row Count 35 (+ 6) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Black Friday flash sale}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Design principles: \newline % Row Count 1 (+ 1) 1. Less is more - less element on the web page, fewer data queries to the database, fewer web requests, fewer system dependencies \newline % Row Count 4 (+ 3) 2. Short critical path - fewer hops among services or merge into one service \newline % Row Count 6 (+ 2) 3. Async processing- use message queues to handle high TPS \newline % Row Count 8 (+ 2) 4. Isolation - isolate static and dynamic contents, isolate processes and databases for rare items \newline % Row Count 10 (+ 2) 5. Overselling is bad. When to decrease the inventory is important \newline % Row Count 12 (+ 2) 6. User experience is important. We definitely don't want to inform users that they have successfully placed orders but later tell them no items are actually available \newline % Row Count 16 (+ 4) Happy shopping! If I missed anything, please leave a comment.% Row Count 18 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{API architecture styles}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694966377_Snipaste_2023-09-17_23-59-19.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{System Design Blueprint: The Ultimate Guide}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694966442_25d7ba1c-b55d-4307-baee-03f05c376f4b_3888x4096.jpg}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Data Structures Used in Daily Life}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694966554_Snipaste_2023-09-18_00-02-18.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How does Twitter Recommend "For You" Timeline?}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694966635_ccaba9d0-ac22-4c2c-a65a-19d3f2fca045_3071x4096.jpg}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Architecture Characteristics}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694966745_Snipaste_2023-09-18_00-05-34.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How do we design effective and safe APIs?}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694966917_Snipaste_2023-09-18_00-08-23.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How to Learn SQL?}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694966986_Snipaste_2023-09-18_00-09-32.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Managing Operational Challenges in Caching}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Cache stampede雪崩} \tn \mymulticolumn{1}{x{3.833cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{自动续期,分布式锁,Staggered} expiration,Consistent hashing,Circuit breakers,Request rate limiting and load shedding} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Cache Penetration 穿透} \tn \mymulticolumn{1}{x{3.833cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}store a placeholder value in the cache to represent non-existent data, bloom filter} \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Hot key problem} \tn \mymulticolumn{1}{x{3.833cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}conduct real-time traffic analysis to promptly detect emerging hot keys,split hot key into small keys and distribute, real-time monitoring can enable the cache system to expand quickly, store hot keys in a local cache, decreasing traffic to the remote cache system.} \tn % Row Count 14 (+ 7) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Large key problem} \tn \mymulticolumn{1}{x{3.833cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}1. Data Sharding 2. Hashing or Digest 3. External Storage 4. Data Compression 5. Database or Document Store} \tn % Row Count 18 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Managing Operational Challenges in Caching}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Cache stampede雪崩} \tn \mymulticolumn{1}{x{3.833cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Staggered expiration,Consistent hashing,Circuit breakers,Request rate limiting and load shedding} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Cache Penetration 穿透} \tn \mymulticolumn{1}{x{3.833cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}store a placeholder value in the cache to represent non-existent data, bloom filter} \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Hot key problem} \tn \mymulticolumn{1}{x{3.833cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}conduct real-time traffic analysis to promptly detect emerging hot keys,split hot key into small keys and distribute, real-time monitoring can enable the cache system to expand quickly, store hot keys in a local cache, decreasing traffic to the remote cache system.} \tn % Row Count 14 (+ 7) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Large key problem} \tn \mymulticolumn{1}{x{3.833cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}1. Data Sharding 2. Hashing or Digest 3. External Storage 4. Data Compression 5. Database or Document Store} \tn % Row Count 18 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{DevOps vs. SRE vs. Platform Engineering}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694967831_Snipaste_2023-09-18_00-23-39.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{A Crash Course in Caching}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694968155_Snipaste_2023-09-18_00-29-01.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{What are the API architectural styles?}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{REST \newline % Row Count 1 (+ 1) Proposed in 2000, REST is the most used style. It is often used between front-end clients and back-end services. It is compliant with 6 architectural constraints. The payload format can be JSON, XML, HTML, or plain text. \newline % Row Count 6 (+ 5) GraphQL \newline % Row Count 7 (+ 1) GraphQL was proposed in 2015 by Meta. It provides a schema and type system, suitable for complex systems where the relationships between entities are graph-like. For example, in the diagram below, GraphQL can retrieve user and order information in one call, while in REST this needs multiple calls. \newline % Row Count 13 (+ 6) GraphQL is not a replacement for REST. It can be built upon existing REST services. \newline % Row Count 15 (+ 2) Web socket \newline % Row Count 16 (+ 1) Web socket is a protocol that provides full-duplex communications over TCP. The clients establish web sockets to receive real-time updates from the back-end services. Unlike REST, which always "pulls" data, web socket enables data to be "pushed". \newline % Row Count 22 (+ 6) Webhook \newline % Row Count 23 (+ 1) Webhooks are usually used by third-party asynchronous API calls. In the diagram below, for example, we use Stripe or Paypal for payment channels and register a webhook for payment results. When a third-party payment service is done, it notifies the payment service if the payment is successful or failed. Webhook calls are usually part of the system's state machine. \newline % Row Count 31 (+ 8) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{What are the API architectural styles? (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{gRPC \newline % Row Count 1 (+ 1) Released in 2016, gRPC is used for communications among microservices. gRPC library handles encoding/decoding and data transmission. \newline % Row Count 4 (+ 3) SOAP \newline % Row Count 5 (+ 1) SOAP stands for Simple Object Access Protocol. Its payload is XML only, suitable for communications between internal systems.% Row Count 8 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How Git commands work}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694968352_Snipaste_2023-09-18_00-32-18.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{a load balancer and an API gateway}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694969060_Snipaste_2023-09-18_00-36-00.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Llama 5.0}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694968772_Snipaste_2023-09-18_00-38-48.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Why is Redis so fast?}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694969027_Snipaste_2023-09-18_00-43-35.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{design a chat application}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694969472_Snipaste_2023-09-18_00-50-57.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{log parsing}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694970180_343435005_3474269186224998_289175492556276190_n.jpg}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{API architectural styles}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694971027_Snipaste_2023-09-18_01-16-54.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How to scale from 0 to millions of users}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Load balancer \newline % Row Count 1 (+ 1) A load balancer evenly distributes incoming traffic among web servers that are defined in a load-balanced set. \newline % Row Count 4 (+ 3) Web servers \newline % Row Count 5 (+ 1) Web server returns HTML pages or JSON response for rendering. \newline % Row Count 7 (+ 2) Databases: vertical scaling and horizontal scaling \newline % Row Count 9 (+ 2) Cache \newline % Row Count 10 (+ 1) A cache is a temporary storage area that stores the result of expensive responses or frequently accessed data in memory so that subsequent requests are served more quickly. \newline % Row Count 14 (+ 4) CDN \newline % Row Count 15 (+ 1) A CDN is a network of geographically dispersed servers used to deliver static content. CDN servers cache static content like images, videos, CSS, JavaScript files, etc. \newline % Row Count 19 (+ 4) Message queue \newline % Row Count 20 (+ 1) A message queue is a durable component, stored in memory, that supports asynchronous communication. \newline % Row Count 23 (+ 3) Logging, metrics, automation \newline % Row Count 24 (+ 1) When working with a small website that runs on a few servers, logging, metrics, and automation support are good practices but not a necessity. However, now that your site has grown to serve a large business, investing in those tools is essential.% Row Count 29 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{CAP theorem}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694971840_Snipaste_2023-09-18_01-30-26.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Capacity Planning}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694972057_Snipaste_2023-09-18_01-34-03.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{E-commerce Workflow}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694972435_Snipaste_2023-09-18_01-40-20.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Live streaming explained}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Step 1: The raw video data is captured by a microphone and camera. The data is sent to the server side. \newline % Row Count 3 (+ 3) Step 2: The video data is compressed and encoded. For example, the compressing algorithm separates the background and other video elements. After compression, the video is encoded to standards such as H.264. The size of the video data is much smaller after this step. \newline % Row Count 9 (+ 6) Step 3: The encoded data is divided into smaller segments, usually seconds in length, so it takes much less time to download or stream. \newline % Row Count 12 (+ 3) Step 4: The segmented data is sent to the streaming server. The streaming server needs to support different devices and network conditions. This is called 'Adaptive Bitrate Streaming.' This means we need to produce multiple files at different bitrates in steps 2 and 3. \newline % Row Count 18 (+ 6) Step 5: The live streaming data is pushed to edge servers supported by CDN (Content Delivery Network.) Millions of viewers can watch the video from an edge server nearby. CDN significantly lowers data transmission latency. \newline % Row Count 23 (+ 5) Step 6: The viewers' devices decode and decompress the video data and play the video in a video player. \newline % Row Count 26 (+ 3) Steps 7 and 8: If the video needs to be stored for replay, the encoded data is sent to a storage server, and viewers can request a replay from it later. \newline % Row Count 30 (+ 4) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Live streaming explained (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Standard protocols for live streaming include: \newline % Row Count 1 (+ 1) RTMP (Real-Time Messaging Protocol): This was originally developed by Macromedia to transmit data between a Flash player and a server. Now it is used for streaming video data over the internet. Note that video conferencing applications like Skype use RTC (Real-Time Communication) protocol for lower latency. \newline % Row Count 8 (+ 7) HLS (HTTP Live Streaming): It requires the H.264 or H.265 encoding. Apple devices accept only HLS format. \newline % Row Count 11 (+ 3) DASH (Dynamic Adaptive Streaming over HTTP): DASH does not support Apple devices. \newline % Row Count 13 (+ 2) Both HLS and DASH support adaptive bitrate streaming. \newline % Row Count 15 (+ 2) Over to you: What are some of the optimizations that can be done in this process? Which type of storage is suitable for video persistence in step 7% Row Count 18 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Algorithms you should know}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694974599_Snipaste_2023-09-18_02-16-26.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{non-blocking queue}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694974891_Snipaste_2023-09-18_02-21-17.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{ELK Stack}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/woshiamiaojiang_1694975254_Snipaste_2023-09-18_02-27-23.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{database isolation levels}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{🔹Serializalble: This is the highest isolation level. Concurrent transactions are guaranteed to be executed in sequence. \newline % Row Count 3 (+ 3) 🔹Repeatable Read: Data read during the transaction stays the same as the transaction starts. \newline % Row Count 5 (+ 2) 🔹Read Committed: Data modification can only be read after the transaction is committed. \newline % Row Count 7 (+ 2) 🔹Read Uncommitted: The data modification can be read by other transactions before a transaction is committed. \newline % Row Count 10 (+ 3) The isolation is guaranteed by MVCC (Multi-Version Consistency Control) and locks. \newline % Row Count 12 (+ 2) The diagram below takes Repeatable Read as an example to demonstrate how MVCC works: \newline % Row Count 14 (+ 2) There are two hidden columns for each row: transaction\_id and roll\_pointer. When transaction A starts, a new Read View with transaction\_id=201 is created. Shortly afterward, transaction B starts, and a new Read View with transaction\_id=202 is created. \newline % Row Count 20 (+ 6) Now transaction A modifies the balance to 200, a new row of the log is created, and the roll\_pointer points to the old row. Before transaction A commits, transaction B reads the balance data. Transaction B finds that transaction\_id 201 is not committed, it reads the next committed \seqsplit{record(transaction\_id=200)}. \newline % Row Count 27 (+ 7) Even when transaction A commits, transaction B still reads data based on the Read View created when transaction B starts. So transaction B always reads the data with balance=100.% Row Count 31 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Why is a solid-state drive (SSD) fast?}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Step 1: "Commands come from the user through the host interface" {[}2{]}. The interface can be Serial ATA (SATA) or PCI Express (PCIe). \newline % Row Count 3 (+ 3) Step 2: "The processor in the SSD controller takes the commands and passes them to the flash controller" {[}2{]}. \newline % Row Count 6 (+ 3) Step 3: "SSDs also have embedded RAM memory, generally for caching purposes and to store mapping information" {[}2{]}. \newline % Row Count 9 (+ 3) Step 4: "The packages of NAND flash memory are organized in gangs, over multiple channels" {[}2{]}. \newline % Row Count 11 (+ 2) The second diagram illustrates how the logical and physical pages are mapped, and why this architecture is fast. \newline % Row Count 14 (+ 3) SSD controller operates multiple FLASH particles in parallel, greatly improving the underlying bandwidth. When we need to write more than one page, the SSD controller can write them in parallel {[}3{]}, whereas the HDD has a single head and it can only read from one head at a time. \newline % Row Count 20 (+ 6) Every time a HOST Page is written, the SSD controller finds a Physical Page to write the data and this mapping is recorded. With this mapping, the next time HOST reads a HOST Page, the SSD knows where to read the data from FLASH {[}3{]}.% Row Count 25 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{At most once, at least once, exactly once}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{\seqsplit{𝐀𝐭-𝐦𝐨𝐬𝐭} 𝐨𝐧𝐜𝐞 \newline % Row Count 1 (+ 1) As the name suggests, at-most once means a message will be delivered not more than once. Messages may be lost but are not redelivered. This is how at-most once delivery works at the high level. \newline % Row Count 5 (+ 4) Use cases: It is suitable for use cases like monitoring metrics, where a small amount of data loss is acceptable. \newline % Row Count 8 (+ 3) \seqsplit{𝐀𝐭-𝐥𝐞𝐚𝐬𝐭} 𝐨𝐧𝐜𝐞 \newline % Row Count 9 (+ 1) With this data delivery semantic, it's acceptable to deliver a message more than once, but no message should be lost. \newline % Row Count 12 (+ 3) Use cases: With at-least once, messages won't be lost but the same message might be delivered multiple times. While not ideal from a user perspective, at-least once delivery semantics are usually good enough for use cases where data duplication is not a big issue or deduplication is possible on the consumer side. For example, with a unique key in each message, a message can be rejected when writing duplicate data to the database. \newline % Row Count 21 (+ 9) \seqsplit{𝐄𝐱𝐚𝐜𝐭𝐥𝐲} 𝐨𝐧𝐜𝐞 \newline % Row Count 22 (+ 1) Exactly once is the most difficult delivery semantic to implement. It is friendly to users, but it has a high cost for the system's performance and complexity. \newline % Row Count 26 (+ 4) Use cases: Financial-related use cases (payment, trading, accounting, etc.). Exactly once is especially important when duplication is not acceptable and the downstream service or third party doesn't support idempotency. \newline % Row Count 31 (+ 5) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{At most once, at least once, exactly once (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Question: what is the difference between message queues vs event streaming platforms such as Kafka, Apache Pulsar, etc?% Row Count 3 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{At most once, at least once, exactly once}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{\seqsplit{𝐀𝐭-𝐦𝐨𝐬𝐭} 𝐨𝐧𝐜𝐞 \newline % Row Count 1 (+ 1) As the name suggests, at-most once means a message will be delivered not more than once. Messages may be lost but are not redelivered. This is how at-most once delivery works at the high level. \newline % Row Count 5 (+ 4) Use cases: It is suitable for use cases like monitoring metrics, where a small amount of data loss is acceptable. \newline % Row Count 8 (+ 3) \seqsplit{𝐀𝐭-𝐥𝐞𝐚𝐬𝐭} 𝐨𝐧𝐜𝐞 \newline % Row Count 9 (+ 1) With this data delivery semantic, it's acceptable to deliver a message more than once, but no message should be lost. \newline % Row Count 12 (+ 3) Use cases: With at-least once, messages won't be lost but the same message might be delivered multiple times. While not ideal from a user perspective, at-least once delivery semantics are usually good enough for use cases where data duplication is not a big issue or deduplication is possible on the consumer side. For example, with a unique key in each message, a message can be rejected when writing duplicate data to the database. \newline % Row Count 21 (+ 9) \seqsplit{𝐄𝐱𝐚𝐜𝐭𝐥𝐲} 𝐨𝐧𝐜𝐞 \newline % Row Count 22 (+ 1) Exactly once is the most difficult delivery semantic to implement. It is friendly to users, but it has a high cost for the system's performance and complexity. \newline % Row Count 26 (+ 4) Use cases: Financial-related use cases (payment, trading, accounting, etc.). Exactly once is especially important when duplication is not acceptable and the downstream service or third party doesn't support idempotency. \newline % Row Count 31 (+ 5) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{At most once, at least once, exactly once (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Question: what is the difference between message queues vs event streaming platforms such as Kafka, Apache Pulsar, etc?% Row Count 3 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}