{"id":957,"date":"2026-10-13T11:00:00","date_gmt":"2026-10-13T05:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/?p=957"},"modified":"2026-11-29T01:29:22","modified_gmt":"2026-11-28T19:59:22","slug":"system-design-interview-questions","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/","title":{"rendered":"System Design Interview Questions: 140+ Q&amp;A for Go Developers"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">System design interview questions are now part of almost every Go developer interview, from fresher roles to senior backend jobs. This post gives you the full list, from basic terms like scalability and latency to classic problems like designing a URL shortener, a chat app and a payment system. Every answer uses simple English, and many include Go code you can run.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You do not need years of experience to start. If you know Go basics, goroutines and REST APIs, you are ready. For Go language questions, see our <a href=\"https:\/\/smitabharat.com\/blog\/golang-questions-and-answers\/\">Golang questions and answers<\/a>, and for a full study plan, use <a href=\"https:\/\/smitabharat.com\/blog\/all-interview-questions\/\">all interview questions with a study path<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What These System Design Interview Questions Cover<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The questions go from basic to advanced in ten sections. So you can stop at the level your role needs, or go all the way to the classic design problems.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The table below shows the sections and the questions in each one.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Section<\/th><th>Level<\/th><th>Questions<\/th><\/tr><\/thead><tbody><tr><td>Basics<\/td><td>Basic<\/td><td>Q1 to Q22<\/td><\/tr><tr><td>Load balancing, networking and APIs<\/td><td>Basic<\/td><td>Q23 to Q39<\/td><\/tr><tr><td>Databases and storage<\/td><td>Intermediate<\/td><td>Q40 to Q59<\/td><\/tr><tr><td>Caching<\/td><td>Intermediate<\/td><td>Q60 to Q70<\/td><\/tr><tr><td>Queues, events and async work<\/td><td>Intermediate<\/td><td>Q71 to Q84<\/td><\/tr><tr><td>Reliability and fault tolerance<\/td><td>Advanced<\/td><td>Q85 to Q98<\/td><\/tr><tr><td>Observability and security<\/td><td>Advanced<\/td><td>Q99 to Q110<\/td><\/tr><tr><td>Go-specific design<\/td><td>Advanced<\/td><td>Q111 to Q124<\/td><\/tr><tr><td>Classic design problems<\/td><td>Advanced<\/td><td>Q125 to Q138<\/td><\/tr><tr><td>How to answer in the interview<\/td><td>All levels<\/td><td>Q139 to Q146<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Every full Go program in this post was run, and its exact output is shown below it. Short snippets that need a server, a database or an external package are marked as examples only.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Most System Design Answers Fit Together<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Almost every answer in this list uses the same building blocks. A request comes through DNS and a CDN, passes a load balancer or API gateway, reaches stateless Go services, and those services use a cache, a database and a message queue.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-1-1024x640.png\" alt=\"System design interview questions diagram showing a typical Go backend architecture with load balancer, services, cache, database and queue\" class=\"wp-image-954\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">A typical backend: clients reach Go services through a load balancer, and the services use Redis, PostgreSQL and a message queue with background workers.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So when a question feels new, start from this picture. Then ask which box needs to change for this problem.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">System Design Interview Questions on Basics<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These first system design interview questions check that you know the words and ideas everyone uses. So even if you are a fresher, start here, because every later answer builds on them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. What is system design?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">System design is the process of planning how the parts of a software system fit together. You decide which services you need, where data lives, how parts talk to each other and how the system grows. In short, it is the blueprint before you write the code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of building a house. You do not start by laying bricks. First, an architect draws where the rooms, pipes and wires go. System design is that drawing for software.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2. What is the difference between system design and system architecture?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">People often use the two words for the same thing, and interviewers usually do too. However, there is a small difference.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Term<\/th><th>Focus<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>System architecture<\/td><td>The big picture and main building blocks<\/td><td>Microservices, a message queue and PostgreSQL<\/td><\/tr><tr><td>System design<\/td><td>Architecture plus detailed choices<\/td><td>Table schema, cache keys, API endpoints<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So architecture is the city map, and design also includes the plan of each building.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. What is the difference between high-level design and low-level design?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">High-level design (HLD) shows the main components and how data flows between them. For example, it shows the load balancer, the API service, the cache, the database and the queue. Low-level design (LLD) goes inside one component. It covers classes or structs, interfaces, function signatures, database tables and error handling.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In a Go interview, HLD questions sound like &#8220;design a URL shortener&#8221;. LLD questions sound like &#8220;write the structs and interfaces for a parking lot&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4. Why do Go developers get system design questions?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go is mainly used for backend services, APIs, cloud tools and microservices. So a Go developer is expected to build services that handle many users, stay up and recover from failure. Interviewers want to see that you can think beyond one function and plan a whole service.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, Go has features that matter in design answers, such as goroutines for concurrency, <code>context<\/code> for timeouts and a fast <code>net\/http<\/code> server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5. What is scalability?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Scalability is the ability of a system to handle more work by adding more resources. For example, if traffic grows from 1,000 to 100,000 users, a scalable system keeps working by adding servers. A system that is not scalable slows down or crashes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Good scalability means the cost grows roughly in line with the load. So doubling the servers should roughly double the capacity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6. What is the difference between vertical scaling and horizontal scaling?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Vertical scaling (scale up) means giving one machine more CPU, RAM or disk. Horizontal scaling (scale out) means adding more machines and spreading the work across them. Most large systems use horizontal scaling, because one machine always has a limit.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Vertical scaling<\/th><th>Horizontal scaling<\/th><\/tr><\/thead><tbody><tr><td>How<\/td><td>Bigger machine<\/td><td>More machines<\/td><\/tr><tr><td>Limit<\/td><td>Hardware maximum<\/td><td>Almost no hard limit<\/td><\/tr><tr><td>Code changes<\/td><td>Usually none<\/td><td>Service must be stateless<\/td><\/tr><tr><td>Failure<\/td><td>One machine is a single point of failure<\/td><td>One machine can fail safely<\/td><\/tr><tr><td>Cost<\/td><td>Gets very expensive at the top<\/td><td>Cheaper commodity machines<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Go services scale out well, because a Go binary is small, starts fast and runs nicely in containers.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-2-1024x640.png\" alt=\"System design interview questions comparison of vertical scaling and horizontal scaling\" class=\"wp-image-955\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Vertical scaling makes one machine bigger, while horizontal scaling adds more machines behind a load balancer.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7. What is latency and what is throughput?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Latency is the time one request takes, for example 120 milliseconds. Throughput is how many requests the system handles per second, for example 5,000 requests per second. They are related but not the same.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A highway is a good analogy. Latency is how long one car takes to reach the end. Throughput is how many cars pass per hour. So you can add more lanes to raise throughput without making any single car faster.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8. Why do we measure p95 and p99 latency instead of the average?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The average hides slow requests. If 99 requests take 10 ms and one takes 2 seconds, the average still looks fine. However, that one user had a terrible experience.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So we use percentiles. p95 means 95% of requests were faster than this value. p99 shows the slowest 1%, which is often where real problems live. Big systems watch p99 closely, because one page may call many services, and one slow call makes the whole page slow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9. What is availability and what does &#8220;five nines&#8221; mean?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Availability is the percentage of time a system works and answers requests. It is often written as a number of nines. The table below shows how much downtime each level allows per year.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Availability<\/th><th>Name<\/th><th>Downtime per year<\/th><\/tr><\/thead><tbody><tr><td>99%<\/td><td>Two nines<\/td><td>About 3.65 days<\/td><\/tr><tr><td>99.9%<\/td><td>Three nines<\/td><td>About 8.8 hours<\/td><\/tr><tr><td>99.99%<\/td><td>Four nines<\/td><td>About 53 minutes<\/td><\/tr><tr><td>99.999%<\/td><td>Five nines<\/td><td>About 5.3 minutes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Each extra nine costs a lot more, because you need more redundancy, automation and testing. So choose the level the business really needs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10. What is the difference between availability and reliability?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Availability asks &#8220;is the system up right now?&#8221;. Reliability asks &#8220;does the system do the right thing, every time, over a long period?&#8221;. A system can be up but still return wrong data, so it is available but not reliable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, a payment service that answers every call but sometimes charges twice is available. However, it is not reliable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11. What are SLA, SLO and SLI?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These three terms describe service quality targets.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>SLI (Service Level Indicator):<\/strong> the real measured number, for example &#8220;99.95% of requests succeeded this month&#8221;.<\/li>\n\n\n<li><strong>SLO (Service Level Objective):<\/strong> the internal target, for example &#8220;99.9% of requests should succeed&#8221;.<\/li>\n\n\n<li><strong>SLA (Service Level Agreement):<\/strong> a contract with customers, with a penalty if you miss it, for example a refund.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So the SLI is what you measure, the SLO is what you aim for and the SLA is what you promise. Teams set the SLO stricter than the SLA, so they get a warning before they break the contract.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12. What is an error budget?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An error budget is the amount of failure your SLO allows. If your SLO is 99.9% success, your error budget is 0.1% of requests. For example, with 10 million requests a month you can fail 10,000 of them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Teams use it to balance speed and safety. If the budget is still large, they ship features faster. If it is nearly used up, they slow down and fix reliability first.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13. What is a single point of failure?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A single point of failure (SPOF) is one part that brings the whole system down when it fails. Common examples are one database server, one load balancer or one network link. You remove a SPOF by adding redundancy, such as a second server that can take over.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In an interview, always scan your diagram and ask &#8220;what happens if this box dies?&#8221;. Then fix each SPOF you find.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14. What is the difference between a stateless and a stateful service?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A stateless service keeps no user data in its own memory between requests. Every request carries what it needs, or the service reads state from a database or cache. A stateful service keeps data in memory, such as a user session or a game room.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Stateless services are easy to scale, because any server can handle any request. So most Go APIs are built stateless, and they store sessions in Redis or a database instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15. What happens when you type a URL in the browser and press Enter?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This classic question tests if you know the full request path. Here is a simple version of the steps.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First, the browser finds the IP address of the domain using DNS.<\/li>\n\n\n<li>Next, it opens a TCP connection, and a TLS handshake sets up HTTPS encryption.<\/li>\n\n\n<li>Then it sends an HTTP request, which often reaches a CDN or load balancer first.<\/li>\n\n\n<li>The load balancer forwards the request to one of the backend servers, for example a Go API.<\/li>\n\n\n<li>The backend reads data from a cache or database and builds a response.<\/li>\n\n\n<li>Finally, the browser receives HTML, CSS and JavaScript and renders the page.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">In a design interview, you can mention where caching happens at each step, for example the DNS cache, the CDN and the application cache.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16. What is DNS and how does it help in system design?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DNS (Domain Name System) turns a name like <code>api.example.com<\/code> into an IP address. It works like the contacts app on your phone, where you tap a name and the phone dials the number.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DNS also helps with design. For example, it can send users to the nearest region (geo DNS) or move traffic away from a failed region. However, DNS answers are cached with a TTL, so changes can take minutes to reach everyone.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17. What is the difference between a monolith and microservices?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A monolith is one application that contains all features and is deployed as one unit. Microservices split the system into small services, and each one owns one business area and deploys on its own.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Monolith<\/th><th>Microservices<\/th><\/tr><\/thead><tbody><tr><td>Deployment<\/td><td>One unit<\/td><td>Each service separately<\/td><\/tr><tr><td>Team size<\/td><td>Best for small teams<\/td><td>Fits many teams<\/td><\/tr><tr><td>Complexity<\/td><td>Simple to start<\/td><td>Network, tracing, many deployments<\/td><\/tr><tr><td>Scaling<\/td><td>Scale everything together<\/td><td>Scale only the busy service<\/td><\/tr><tr><td>Data<\/td><td>One shared database<\/td><td>Each service owns its data<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So start with a well-structured monolith for a new product. Then split it into services when teams or traffic make the monolith painful.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18. What is a modular monolith?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A modular monolith is one deployable application, but the code is split into clear modules with strict boundaries. For example, <code>orders<\/code>, <code>payments<\/code> and <code>users<\/code> live in separate Go packages and talk only through interfaces.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It gives you the simple deployment of a monolith and the clean boundaries of microservices. So later, you can pull one module out into its own service with less pain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19. What is the CAP theorem?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The CAP theorem says a distributed system can only guarantee two of these three properties when the network breaks.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Consistency (C):<\/strong> every read gets the latest write.<\/li>\n\n\n<li><strong>Availability (A):<\/strong> every request gets a response, even if it is not the latest data.<\/li>\n\n\n<li><strong>Partition tolerance (P):<\/strong> the system keeps working when messages between nodes are lost.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Network partitions always happen in real life, so P is not optional. This means the real choice is between C and A during a partition. A bank balance usually picks consistency (CP). A social media like counter usually picks availability (AP).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20. What is PACELC and how does it extend CAP?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PACELC adds the normal case to CAP. It says: if there is a Partition, choose Availability or Consistency, Else (no partition), choose Latency or Consistency.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So even when the network is fine, strong consistency costs time, because nodes must agree before answering. For example, a database that waits for every replica gives fresh data but slower writes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21. What is the difference between strong consistency and eventual consistency?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With strong consistency, after a write finishes, every reader sees the new value at once. With eventual consistency, readers may see old data for a short time, but all copies become the same soon.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, when you change your profile photo, friends may see the old photo for a few seconds. That is eventual consistency, and it is fine there. However, a bank transfer needs strong consistency, so the money never appears in two places.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q22. What are the main building blocks of a typical web system?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Most backend designs use the same set of parts. The table below lists them with their job.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Building block<\/th><th>Job<\/th><\/tr><\/thead><tbody><tr><td>DNS<\/td><td>Turns names into IP addresses<\/td><\/tr><tr><td>CDN<\/td><td>Serves static files close to users<\/td><\/tr><tr><td>Load balancer<\/td><td>Spreads requests across servers<\/td><\/tr><tr><td>API gateway<\/td><td>Auth, rate limits and routing at the edge<\/td><\/tr><tr><td>Application servers<\/td><td>Run the business logic, for example Go services<\/td><\/tr><tr><td>Cache<\/td><td>Keeps hot data in memory, for example Redis<\/td><\/tr><tr><td>Database<\/td><td>Stores data permanently<\/td><\/tr><tr><td>Message queue<\/td><td>Moves slow work to the background<\/td><\/tr><tr><td>Object storage<\/td><td>Stores files and images, for example S3<\/td><\/tr><tr><td>Monitoring<\/td><td>Logs, metrics, traces and alerts<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So when you draw a design, you can pick from this list and explain why each part is there.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">System Design Interview Questions on Load Balancing, Networking and APIs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This group of system design interview questions is about how requests reach your Go service and how services talk to each other. Interviewers ask these in almost every backend round.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q23. What is a load balancer?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A load balancer sits in front of a group of servers and spreads incoming requests across them. So no single server gets overloaded, and if one server dies, traffic goes to the healthy ones.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a bank with five counters and one person at the door who sends each customer to a free counter. That person is the load balancer. Examples include NGINX, HAProxy, Envoy and cloud load balancers such as AWS ALB.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q24. What is the difference between a Layer 4 and a Layer 7 load balancer?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A Layer 4 (L4) load balancer works with TCP or UDP connections. It only sees IP addresses and ports, so it is very fast but cannot read the HTTP request. A Layer 7 (L7) load balancer reads the HTTP request, so it can route by path, header or cookie.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Layer 4<\/th><th>Layer 7<\/th><\/tr><\/thead><tbody><tr><td>Sees<\/td><td>IP and port<\/td><td>URL, headers, cookies<\/td><\/tr><tr><td>Speed<\/td><td>Faster<\/td><td>A little slower<\/td><\/tr><tr><td>Routing<\/td><td>By connection<\/td><td>By path, host or header<\/td><\/tr><tr><td>TLS<\/td><td>Usually passes it through<\/td><td>Often ends TLS here<\/td><\/tr><tr><td>Example use<\/td><td>Raw TCP, gRPC streams, databases<\/td><td>REST APIs, web apps<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So use L7 when you need smart routing like <code>\/api\/orders<\/code> to the order service. Use L4 when you only need fast spreading of connections.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q25. What load balancing algorithms do you know?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are the common ones, from simple to smart.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Round robin:<\/strong> send each request to the next server in a circle.<\/li>\n\n\n<li><strong>Weighted round robin:<\/strong> bigger servers get more requests.<\/li>\n\n\n<li><strong>Least connections:<\/strong> send to the server with the fewest open connections.<\/li>\n\n\n<li><strong>Least response time:<\/strong> send to the fastest server right now.<\/li>\n\n\n<li><strong>IP hash:<\/strong> the same client IP always goes to the same server.<\/li>\n\n\n<li><strong>Consistent hashing:<\/strong> the same key goes to the same server, and adding a server moves only a few keys.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Round robin is fine when all requests cost about the same. However, least connections works better when some requests are slow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a small Go program that shows round robin across three servers.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ RoundRobin picks servers one after another in a circle.\ntype RoundRobin struct {\n    servers []string\n    next    int\n}\n\nfunc (r *RoundRobin) Pick() string {\n    server := r.servers[r.next]\n    r.next = (r.next + 1) % len(r.servers) \/\/ move to the next one, wrap around\n    return server\n}\n\nfunc main() {\n    lb := &amp;RoundRobin{servers: []string{\"app-1\", \"app-2\", \"app-3\"}}\n    for request := 1; request &lt;= 5; request++ {\n        fmt.Printf(\"request %d goes to %s\\n\", request, lb.Pick())\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>request 1 goes to app-1\nrequest 2 goes to app-2\nrequest 3 goes to app-3\nrequest 4 goes to app-1\nrequest 5 goes to app-2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In a real load balancer, many goroutines call <code>Pick<\/code> at the same time. So you would protect <code>next<\/code> with a mutex or use <code>sync\/atomic<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q26. What are sticky sessions and why should you avoid them?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sticky sessions mean the load balancer always sends one user to the same server, usually with a cookie. Teams use them when the server keeps session data in memory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, they cause problems. Load becomes uneven, and if that server dies, the user loses the session. So the better design is a stateless Go service that keeps sessions in Redis or uses tokens.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q27. What is a health check?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A health check is a small request the load balancer sends to each server, for example <code>GET \/healthz<\/code> every 10 seconds. If a server fails several checks in a row, the load balancer stops sending it traffic. When it passes again, traffic comes back.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a simple health endpoint in Go.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"log\"\n    \"net\/http\"\n)\n\nfunc main() {\n    mux := http.NewServeMux()\n\n    \/\/ Liveness: the process is running.\n    mux.HandleFunc(\"GET \/healthz\", func(w http.ResponseWriter, r *http.Request) {\n        w.WriteHeader(http.StatusOK)\n        w.Write([]byte(\"ok\"))\n    })\n\n    log.Fatal(http.ListenAndServe(\":8080\", mux))\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>\"GET \/healthz\"<\/code> pattern with a method uses the routing added to <code>net\/http<\/code> in Go 1.22. So you do not need a third-party router for simple APIs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q28. What is a reverse proxy, and how is it different from a forward proxy?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A reverse proxy sits in front of your servers and receives requests on their behalf. Clients do not know which server answered. It can do TLS, caching, compression and load balancing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A forward proxy sits in front of clients and sends requests out on their behalf, for example a company proxy that controls internet access. So the reverse proxy protects servers, and the forward proxy protects or controls clients. In Go, <code>httputil.ReverseProxy<\/code> from <code>net\/http\/httputil<\/code> lets you build a simple reverse proxy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q29. What is an API gateway?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An API gateway is a single entry point for all client requests to your microservices. It handles common jobs in one place, so each service does not repeat them.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Routing requests to the right service.<\/li>\n\n\n<li>Authentication and checking tokens.<\/li>\n\n\n<li>Rate limiting and quotas.<\/li>\n\n\n<li>Request logging, metrics and tracing.<\/li>\n\n\n<li>Turning one client call into several service calls.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For example, a mobile app calls <code>api.shop.com<\/code>, and the gateway sends <code>\/orders<\/code> to the order service and <code>\/users<\/code> to the user service. Examples are Kong, AWS API Gateway, Envoy based gateways and custom Go gateways.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q30. What is the difference between an API gateway and a load balancer?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A load balancer spreads traffic across copies of the same service. An API gateway routes traffic to different services and adds features like auth and rate limits. In many systems you have both, with the gateway first and a load balancer in front of each service.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q31. What is a CDN?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A CDN (Content Delivery Network) is a group of servers around the world that keep copies of your static files, such as images, CSS, JavaScript and videos. A user in Mumbai gets the file from a nearby server instead of your main server in the US. So pages load faster, and your servers handle less traffic.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Some CDNs also cache API responses that are the same for everyone, such as a product list. Popular examples include Cloudflare, Amazon CloudFront and Akamai.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q32. What is the difference between REST, gRPC and GraphQL?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">All three are ways for clients and services to talk. The table below compares them.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>REST<\/th><th>gRPC<\/th><th>GraphQL<\/th><\/tr><\/thead><tbody><tr><td>Format<\/td><td>JSON over HTTP<\/td><td>Protocol Buffers over HTTP\/2<\/td><td>JSON over HTTP<\/td><\/tr><tr><td>Contract<\/td><td>OpenAPI (optional)<\/td><td><code>.proto<\/code> file (required)<\/td><td>Schema (required)<\/td><\/tr><tr><td>Speed<\/td><td>Good<\/td><td>Very fast, small messages<\/td><td>Good<\/td><\/tr><tr><td>Streaming<\/td><td>Limited<\/td><td>Built in, both ways<\/td><td>Subscriptions<\/td><\/tr><tr><td>Best for<\/td><td>Public APIs, browsers<\/td><td>Service to service<\/td><td>Flexible frontend queries<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So a common Go setup is REST or GraphQL for the frontend and gRPC between internal services. You can read more in our <a href=\"https:\/\/smitabharat.com\/blog\/go-grpc-interview-questions-part-22\/\">Go gRPC interview questions<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q33. What is the difference between HTTP\/1.1, HTTP\/2 and HTTP\/3?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">HTTP\/1.1 sends one request at a time on each connection, so browsers open many connections. HTTP\/2 sends many requests at once over one connection (multiplexing) and compresses headers. HTTP\/3 runs over QUIC on UDP, so one lost packet does not block all other streams, and connections start faster.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go&#8217;s <code>net\/http<\/code> supports HTTP\/2 automatically over TLS. gRPC needs HTTP\/2, because it uses its streams.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q34. What is the difference between polling, long polling, WebSockets and server-sent events?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These are ways to get new data from the server to the client. The table below shows when each one fits.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>How it works<\/th><th>Best for<\/th><\/tr><\/thead><tbody><tr><td>Short polling<\/td><td>Client asks every few seconds<\/td><td>Simple dashboards<\/td><\/tr><tr><td>Long polling<\/td><td>Server holds the request until data arrives<\/td><td>Simple notifications<\/td><\/tr><tr><td>Server-sent events (SSE)<\/td><td>One long HTTP stream from server to client<\/td><td>Live feeds, AI text streaming<\/td><\/tr><tr><td>WebSockets<\/td><td>Full two-way connection<\/td><td>Chat, games, live collaboration<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So pick SSE when only the server sends updates, and WebSockets when both sides talk. Go handles thousands of open connections well, because each one only needs a cheap goroutine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q35. What is idempotency and why does it matter in APIs?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An operation is idempotent when doing it many times has the same effect as doing it once. For example, <code>PUT \/users\/7<\/code> with the same body always leaves the same user. <code>DELETE<\/code> is also idempotent. A plain <code>POST \/payments<\/code> is not, because two calls could charge twice.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It matters because networks fail. A client may not get the response and will retry. So for payments and orders, clients send an <code>Idempotency-Key<\/code> header, and the server remembers the result for that key.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a small Go program that shows the idea with an in-memory store.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"sync\"\n)\n\n\/\/ PaymentService remembers the result of each idempotency key.\ntype PaymentService struct {\n    mu      sync.Mutex\n    results map[string]string\n    charges int\n}\n\nfunc (s *PaymentService) Pay(key string, amount int) string {\n    s.mu.Lock()\n    defer s.mu.Unlock()\n\n    \/\/ Seen this key before? Return the saved result, do not charge again.\n    if result, ok := s.results[key]; ok {\n        return result + \" (replayed)\"\n    }\n    s.charges++\n    result := fmt.Sprintf(\"charged %d rupees\", amount)\n    s.results[key] = result\n    return result\n}\n\nfunc main() {\n    svc := &amp;PaymentService{results: map[string]string{}}\n    fmt.Println(svc.Pay(\"order-101\", 500))\n    fmt.Println(svc.Pay(\"order-101\", 500)) \/\/ client retry after a timeout\n    fmt.Println(svc.Pay(\"order-102\", 250))\n    fmt.Println(\"real charges:\", svc.charges)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>charged 500 rupees\ncharged 500 rupees (replayed)\ncharged 250 rupees\nreal charges: 2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In production, you keep the keys in Redis or the database with an expiry time, so every server instance sees them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q36. How do you design pagination for a large API list?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are two main types. Offset pagination uses <code>?page=5&amp;limit=20<\/code>, which maps to <code>OFFSET 80 LIMIT 20<\/code> in SQL. It is simple, but it gets slow on deep pages and can skip or repeat rows when new data arrives.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Cursor (keyset) pagination returns a cursor, such as the last seen ID, and the next query is <code>WHERE id &gt; last_id ORDER BY id LIMIT 20<\/code>. It stays fast on any page and is stable when data changes. So use cursor pagination for feeds and big tables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q37. How do you version an API?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You version an API so old clients keep working when you change it. Common ways are a version in the path (<code>\/v1\/orders<\/code>), a header (<code>Accept: application\/vnd.shop.v2+json<\/code>) or a query parameter. The path version is the most common, because it is clear and easy to route.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, try not to break clients at all. Add new fields instead of renaming old ones, and keep the old version running until clients move.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q38. What is service discovery?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In microservices, servers start and stop all the time, so their IP addresses change. Service discovery is how a service finds the current address of another service.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Kubernetes, you call a stable Service name like <code>http:\/\/orders:8080<\/code>, and Kubernetes DNS finds a healthy pod. Outside Kubernetes, tools like Consul or etcd keep a registry of live instances. Our <a href=\"https:\/\/smitabharat.com\/blog\/kubernetes-interview-questions\/\">Kubernetes interview questions<\/a> cover Services in more detail.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q39. What is a service mesh?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A service mesh adds a small proxy (a sidecar) next to each service, or a shared node proxy. The proxies handle retries, timeouts, mTLS encryption and metrics for all service-to-service calls. So your Go code stays simple, and the platform team controls these rules in one place.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Istio and Linkerd are well-known examples. However, a mesh adds moving parts, so small systems often do not need one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">System Design Interview Questions on Databases and Storage<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Most system design interview questions come down to one hard part: the data. So this section covers how to pick, grow and protect a database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q40. How do you choose between SQL and NoSQL databases?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SQL databases, such as PostgreSQL and MySQL, store data in tables with a fixed schema and support joins and transactions. NoSQL databases come in several types, such as document (MongoDB), key-value (Redis, DynamoDB), wide-column (Cassandra) and graph (Neo4j).<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>SQL<\/th><th>NoSQL<\/th><\/tr><\/thead><tbody><tr><td>Schema<\/td><td>Fixed tables and columns<\/td><td>Flexible, per item<\/td><\/tr><tr><td>Relations<\/td><td>Joins and foreign keys<\/td><td>Usually avoided<\/td><\/tr><tr><td>Transactions<\/td><td>Strong ACID<\/td><td>Varies, often per item<\/td><\/tr><tr><td>Scaling<\/td><td>Mostly vertical plus read replicas<\/td><td>Built for horizontal scaling<\/td><\/tr><tr><td>Best for<\/td><td>Orders, payments, users<\/td><td>Huge scale, simple access patterns<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So start with PostgreSQL for most business systems. Pick NoSQL when you have a clear reason, such as massive write volume or a simple key lookup at huge scale.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q41. What are ACID properties?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ACID describes how a database transaction stays safe.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Atomicity:<\/strong> all steps happen, or none do. A money transfer never debits without crediting.<\/li>\n\n\n<li><strong>Consistency:<\/strong> the data always follows the rules, such as constraints and foreign keys.<\/li>\n\n\n<li><strong>Isolation:<\/strong> transactions running at the same time do not see each other&#8217;s half-done work.<\/li>\n\n\n<li><strong>Durability:<\/strong> once committed, data survives a crash.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In Go, you get a transaction with <code>db.BeginTx(ctx, nil)<\/code>, then call <code>tx.Commit()<\/code> or <code>tx.Rollback()<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q42. What is BASE?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">BASE is the style many NoSQL systems follow. It stands for Basically Available, Soft state and Eventually consistent. So the system stays up and fast, but replicas may disagree for a short time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ACID favours correctness, while BASE favours availability and scale. Many real systems use both, for example ACID for payments and BASE for activity feeds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q43. What are transaction isolation levels?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Isolation levels decide how much one transaction can see of another one that is still running. The table below shows the four standard levels, from weakest to strongest.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Level<\/th><th>Dirty read<\/th><th>Non-repeatable read<\/th><th>Phantom read<\/th><\/tr><\/thead><tbody><tr><td>Read uncommitted<\/td><td>Possible<\/td><td>Possible<\/td><td>Possible<\/td><\/tr><tr><td>Read committed<\/td><td>Prevented<\/td><td>Possible<\/td><td>Possible<\/td><\/tr><tr><td>Repeatable read<\/td><td>Prevented<\/td><td>Prevented<\/td><td>Possible in the SQL standard<\/td><\/tr><tr><td>Serializable<\/td><td>Prevented<\/td><td>Prevented<\/td><td>Prevented<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL uses read committed by default, and MySQL InnoDB uses repeatable read. Stronger levels are safer but can cause more waiting or retries. In Go, you set it with <code>sql.TxOptions{Isolation: sql.LevelSerializable}<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q44. What is a database index and what does it cost?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An index is a sorted structure, usually a B-tree, that helps the database find rows without scanning the whole table. It works like the index at the back of a book, where you jump straight to the right page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, indexes are not free. Every insert and update must also update each index, and indexes use disk and memory. So add indexes for the columns you filter, join and sort on most, and check with <code>EXPLAIN<\/code> that the database uses them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q45. What is database replication?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Replication keeps copies of the same data on several database servers. The most common setup is one primary (leader) that takes writes and several replicas (followers) that copy changes and serve reads.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It gives you two benefits. First, reads scale out, because replicas share the read load. Second, if the primary fails, a replica can be promoted, so you get high availability.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q46. What is the difference between synchronous and asynchronous replication?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With synchronous replication, the primary waits until a replica confirms the write before telling the client &#8220;done&#8221;. So no committed data is lost if the primary dies, but writes are slower. With asynchronous replication, the primary answers at once and replicas catch up later. Writes are fast, but the last few writes can be lost in a crash, and replicas may lag.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Many systems use a mix. For example, one replica is synchronous and the rest are asynchronous.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q47. What is replication lag and how do you handle it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Replication lag is the delay before a write on the primary shows up on a replica. For example, a user updates their name and then reloads the page, but the read goes to a replica that still has the old name.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are common fixes.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Read your own writes:<\/strong> read from the primary for a short time after a user writes.<\/li>\n\n\n<li><strong>Sticky reads:<\/strong> send a user&#8217;s reads to the primary for a few seconds after an update.<\/li>\n\n\n<li><strong>Version check:<\/strong> read from a replica only if it has reached the write&#8217;s version.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q48. What is the difference between partitioning and sharding?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Partitioning splits one big table into smaller pieces. Sharding is partitioning across different database servers, so each server holds only part of the data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, an <code>orders<\/code> table with a billion rows can be split by <code>user_id<\/code>. Users 1 to 1 million go to shard 1, the next million go to shard 2, and so on. Each shard is smaller, so queries are faster and writes spread across machines.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q49. What sharding strategies do you know?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The table below compares the common ways to decide which shard holds a row.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Strategy<\/th><th>How it works<\/th><th>Good<\/th><th>Watch out for<\/th><\/tr><\/thead><tbody><tr><td>Range<\/td><td>By value range, for example dates<\/td><td>Easy range queries<\/td><td>Hot shard for new data<\/td><\/tr><tr><td>Hash<\/td><td><code>hash(key) % N<\/code><\/td><td>Even spread<\/td><td>Adding shards moves most keys<\/td><\/tr><tr><td>Consistent hashing<\/td><td>Keys and shards on a ring<\/td><td>Few keys move on change<\/td><td>More complex<\/td><\/tr><tr><td>Directory<\/td><td>A lookup table maps key to shard<\/td><td>Full control<\/td><td>The table is a dependency<\/td><\/tr><tr><td>Geographic<\/td><td>By user region<\/td><td>Low latency, data laws<\/td><td>Uneven regions<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So hash-based sharding by user ID is a common default. Pick a shard key that spreads load evenly and keeps one user&#8217;s data together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q50. What is a hot partition and how do you fix it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A hot partition (or hot shard) is one shard that gets far more traffic than the others. For example, if you shard tweets by user, a celebrity with 100 million followers makes one shard very busy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can fix it by adding a random suffix to hot keys to spread them, caching hot data in front, or giving very large tenants their own shard.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q51. What is consistent hashing?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Consistent hashing places both servers and keys on a circle (a ring) of hash values. Each key belongs to the first server found by moving clockwise from the key&#8217;s position. When you add or remove a server, only the keys next to it move. With plain <code>hash % N<\/code>, almost every key would move.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Real systems put each server on the ring many times as &#8220;virtual nodes&#8221;, so the load spreads evenly. Here is a small working version in Go.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"hash\/crc32\"\n    \"sort\"\n    \"strconv\"\n)\n\n\/\/ Ring is a consistent hash ring with virtual nodes.\ntype Ring struct {\n    hashes []uint32          \/\/ sorted positions on the ring\n    owner  map[uint32]string \/\/ position -&gt; server name\n}\n\nfunc NewRing(servers []string, virtualNodes int) *Ring {\n    r := &amp;Ring{owner: map[uint32]string{}}\n    for _, s := range servers {\n        for i := 0; i &lt; virtualNodes; i++ {\n            h := crc32.ChecksumIEEE([]byte(s + \"#\" + strconv.Itoa(i)))\n            r.hashes = append(r.hashes, h)\n            r.owner[h] = s\n        }\n    }\n    sort.Slice(r.hashes, func(i, j int) bool { return r.hashes[i] &lt; r.hashes[j] })\n    return r\n}\n\n\/\/ Get finds the first server clockwise from the key.\nfunc (r *Ring) Get(key string) string {\n    h := crc32.ChecksumIEEE([]byte(key))\n    i := sort.Search(len(r.hashes), func(i int) bool { return r.hashes[i] &gt;= h })\n    if i == len(r.hashes) {\n        i = 0 \/\/ wrap around the circle\n    }\n    return r.owner[r.hashes[i]]\n}\n\nfunc main() {\n    before := NewRing([]string{\"cache-a\", \"cache-b\", \"cache-c\"}, 100)\n    after := NewRing([]string{\"cache-a\", \"cache-b\", \"cache-c\", \"cache-d\"}, 100)\n\n    moved := 0\n    total := 10000\n    for i := 0; i &lt; total; i++ {\n        key := \"user:\" + strconv.Itoa(i)\n        if before.Get(key) != after.Get(key) {\n            moved++\n        }\n    }\n    fmt.Printf(\"keys moved after adding a server: %d of %d\\n\", moved, total)\n    fmt.Println(\"moved less than half:\", moved &lt; total\/2)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>keys moved after adding a server: 2682 of 10000\nmoved less than half: true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So adding a fourth server moved about a quarter of the keys, which is close to the ideal. With <code>hash % N<\/code>, about three quarters would have moved. Redis Cluster uses a related idea with 16,384 fixed hash slots, and Cassandra and DynamoDB use rings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q52. What is the difference between normalization and denormalization?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Normalization removes duplicate data by splitting it into related tables. For example, the customer name lives only in <code>customers<\/code>, and <code>orders<\/code> keeps just <code>customer_id<\/code>. This keeps data correct and easy to update.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Denormalization copies some data on purpose to make reads faster, for example storing <code>customer_name<\/code> inside <code>orders<\/code> to avoid a join. So normalize first, then denormalize the hot read paths when you measure a real need.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q53. When would you use object storage, block storage and file storage?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each type of storage fits a different kind of data.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Type<\/th><th>Example<\/th><th>Best for<\/th><\/tr><\/thead><tbody><tr><td>Object storage<\/td><td>Amazon S3, Google Cloud Storage<\/td><td>Images, videos, backups, logs<\/td><\/tr><tr><td>Block storage<\/td><td>AWS EBS volumes<\/td><td>Database disks<\/td><\/tr><tr><td>File storage<\/td><td>AWS EFS, NFS<\/td><td>Shared folders between servers<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So never store large files inside your database. Put them in object storage, and keep only the file key and metadata in the database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q54. How do you let users upload large files?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not stream big files through your Go API if you can avoid it. Instead, the API creates a short-lived pre-signed URL for object storage, and the client uploads straight to S3 with it. Then the client tells your API the upload finished, or an S3 event triggers a background job.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For very large files, use multipart upload, so the file goes in chunks and a failed chunk can retry alone. This keeps your servers free and makes uploads faster.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q55. What is database connection pooling and how does Go handle it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Opening a database connection is slow, so a pool keeps a set of open connections and reuses them. In Go, <code>*sql.DB<\/code> is already a pool, not a single connection. So you create it once at startup and share it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should tune the pool with these settings.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>db, err := sql.Open(\"pgx\", dsn)\nif err != nil {\n    log.Fatal(err)\n}\ndb.SetMaxOpenConns(25)                  \/\/ upper limit of open connections\ndb.SetMaxIdleConns(25)                  \/\/ keep connections ready for reuse\ndb.SetConnMaxLifetime(30 * time.Minute) \/\/ recycle old connections\ndb.SetConnMaxIdleTime(5 * time.Minute)  \/\/ close connections idle too long<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Remember that the database has a total connection limit. So if 20 pods each open 25 connections, PostgreSQL needs room for 500. For many pods, add a pooler like PgBouncer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q56. What is the N+1 query problem?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The N+1 problem happens when you run one query to get a list, then one more query for each item. For example, you load 100 orders, then run 100 separate queries for each customer. That is 101 trips to the database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The fix is to load related data in one go, with a join or a <code>WHERE id IN (...)<\/code> query. Then you match the results in Go with a map.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q57. What is CQRS?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">CQRS (Command Query Responsibility Segregation) means using separate models for writes (commands) and reads (queries). Writes go to a normalized database that keeps the rules. Reads come from a separate view built for fast queries, such as a denormalized table or a search index.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It helps when reads and writes are very different, for example an e-commerce site with heavy search. However, it adds complexity and eventual consistency, so use it only where it pays off.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q58. What is event sourcing?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With event sourcing, you do not store only the current state. Instead, you store every change as an event, such as <code>MoneyDeposited<\/code> and <code>MoneyWithdrawn<\/code>, and you rebuild the current state by replaying the events.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It gives you a full audit history and lets you rebuild views later. However, it is harder to query and to change event formats. So it suits banking, ledgers and audit-heavy systems more than simple CRUD apps.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q59. How do you back up a database and plan for disaster recovery?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You need regular full backups plus continuous logs, such as PostgreSQL WAL archiving, so you can restore to any point in time. Keep copies in another region and test restores on a schedule, because an untested backup may not work.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Two numbers guide the plan. RPO (Recovery Point Objective) is how much data you can afford to lose, for example 5 minutes. RTO (Recovery Time Objective) is how fast you must be back up, for example 1 hour.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">System Design Interview Questions on Caching<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Caching is the fastest way to make a slow system feel fast, so these system design interview questions come up often. You need to know where to cache, how to keep the cache fresh and what can go wrong.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q60. What is caching and where can you cache data?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A cache stores a copy of data in a faster place, usually memory, so you do not fetch or compute it again. For example, reading from Redis takes well under a millisecond, while a complex SQL query may take 50 ms.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can cache at many layers.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Browser cache:<\/strong> files and API responses with <code>Cache-Control<\/code> headers.<\/li>\n\n\n<li><strong>CDN:<\/strong> static files and public API responses near the user.<\/li>\n\n\n<li><strong>In-process cache:<\/strong> a Go map or an LRU inside each service instance.<\/li>\n\n\n<li><strong>Distributed cache:<\/strong> Redis or Memcached shared by all instances.<\/li>\n\n\n<li><strong>Database cache:<\/strong> the database&#8217;s own buffer pool.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q61. What is the difference between a local cache and a distributed cache?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A local (in-process) cache lives inside each Go process. It is the fastest, because there is no network call. However, every pod has its own copy, so data can differ between pods and memory use multiplies.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A distributed cache like Redis is shared by all pods. It costs a network trip, but every instance sees the same data. Many systems use both, with a small local cache for very hot keys and Redis for everything else.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q62. What caching strategies do you know?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The table below compares the main ways to keep a cache and database in step.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Strategy<\/th><th>How it works<\/th><th>Good<\/th><th>Risk<\/th><\/tr><\/thead><tbody><tr><td>Cache-aside (lazy loading)<\/td><td>App reads cache, on a miss reads DB and fills cache<\/td><td>Simple, caches only what is used<\/td><td>First read is slow, stale data possible<\/td><\/tr><tr><td>Read-through<\/td><td>Cache library loads from DB on a miss<\/td><td>Clean app code<\/td><td>Needs cache support<\/td><\/tr><tr><td>Write-through<\/td><td>Write to cache and DB together<\/td><td>Cache always fresh<\/td><td>Slower writes<\/td><\/tr><tr><td>Write-behind (write-back)<\/td><td>Write to cache, DB updated later<\/td><td>Very fast writes<\/td><td>Data loss if cache dies<\/td><\/tr><tr><td>Write-around<\/td><td>Write only to DB, cache fills on read<\/td><td>Avoids caching unread data<\/td><td>First read is a miss<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So cache-aside is the most common pattern in Go services. Here is how it looks.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"sync\"\n)\n\n\/\/ fakeDB pretends to be a slow database.\nvar dbCalls int\n\nfunc loadUserFromDB(id int) string {\n    dbCalls++\n    return fmt.Sprintf(\"user-%d\", id)\n}\n\ntype UserCache struct {\n    mu    sync.RWMutex\n    items map[int]string\n}\n\n\/\/ GetUser uses the cache-aside pattern.\nfunc (c *UserCache) GetUser(id int) string {\n    c.mu.RLock()\n    name, ok := c.items[id]\n    c.mu.RUnlock()\n    if ok {\n        return name \/\/ cache hit\n    }\n\n    name = loadUserFromDB(id) \/\/ cache miss: go to the database\n    c.mu.Lock()\n    c.items[id] = name \/\/ save for next time\n    c.mu.Unlock()\n    return name\n}\n\nfunc main() {\n    cache := &amp;UserCache{items: map[int]string{}}\n    for _, id := range []int{7, 7, 9, 7, 9} {\n        fmt.Println(cache.GetUser(id))\n    }\n    fmt.Println(\"database calls:\", dbCalls)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>user-7\nuser-7\nuser-9\nuser-7\nuser-9\ndatabase calls: 2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Five reads needed only two database calls. In a real service, the map would be Redis, and each entry would have a TTL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q63. What is cache invalidation, and why is it hard?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Cache invalidation means removing or updating cached data when the source data changes. It is hard because the cache and the database are two separate systems, so updates can happen in the wrong order and leave old data in the cache.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A safe common approach is this: update the database first, then delete the cache key (not update it). The next read loads fresh data. Also, always set a TTL, so even a missed delete fixes itself after some time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q64. What is TTL in caching?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">TTL (time to live) is how long a cache entry stays before it expires. For example, a product price might have a TTL of 5 minutes, and a country list might have a TTL of 24 hours.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A short TTL means fresher data but more database load. A long TTL means less load but older data. Adding a small random amount to each TTL (jitter) stops many keys from expiring at the same moment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q65. What cache eviction policies do you know?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When the cache is full, an eviction policy decides what to remove.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>LRU (Least Recently Used):<\/strong> remove the item not used for the longest time. This is the most common choice.<\/li>\n\n\n<li><strong>LFU (Least Frequently Used):<\/strong> remove the item used the fewest times.<\/li>\n\n\n<li><strong>FIFO (First In, First Out):<\/strong> remove the oldest item.<\/li>\n\n\n<li><strong>TTL-based:<\/strong> remove items when they expire.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Redis supports several of these, for example the <code>allkeys-lru<\/code> policy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q66. How do you build an LRU cache in Go?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An LRU cache needs two things: a map for fast lookup and a doubly linked list to track the order of use. Go&#8217;s <code>container\/list<\/code> gives you the list. Here is a small version.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"container\/list\"\n    \"fmt\"\n)\n\ntype entry struct {\n    key   string\n    value int\n}\n\n\/\/ LRU keeps the most recently used item at the front of the list.\ntype LRU struct {\n    capacity int\n    order    *list.List               \/\/ front = newest, back = oldest\n    items    map[string]*list.Element \/\/ key -&gt; list node\n}\n\nfunc NewLRU(capacity int) *LRU {\n    return &amp;LRU{capacity: capacity, order: list.New(), items: map[string]*list.Element{}}\n}\n\nfunc (c *LRU) Get(key string) (int, bool) {\n    if el, ok := c.items[key]; ok {\n        c.order.MoveToFront(el) \/\/ just used, so make it newest\n        return el.Value.(*entry).value, true\n    }\n    return 0, false\n}\n\nfunc (c *LRU) Put(key string, value int) {\n    if el, ok := c.items[key]; ok {\n        el.Value.(*entry).value = value\n        c.order.MoveToFront(el)\n        return\n    }\n    if c.order.Len() == c.capacity {\n        oldest := c.order.Back() \/\/ remove the least recently used item\n        c.order.Remove(oldest)\n        delete(c.items, oldest.Value.(*entry).key)\n        fmt.Println(\"evicted:\", oldest.Value.(*entry).key)\n    }\n    c.items[key] = c.order.PushFront(&amp;entry{key, value})\n}\n\nfunc main() {\n    cache := NewLRU(2)\n    cache.Put(\"a\", 1)\n    cache.Put(\"b\", 2)\n    cache.Get(\"a\")    \/\/ \"a\" is now the newest\n    cache.Put(\"c\", 3) \/\/ cache is full, so \"b\" goes\n    _, found := cache.Get(\"b\")\n    fmt.Println(\"b still cached:\", found)\n    value, _ := cache.Get(\"a\")\n    fmt.Println(\"a =\", value)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>evicted: b\nb still cached: false\na = 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Both <code>Get<\/code> and <code>Put<\/code> run in O(1) time. For use across goroutines, add a <code>sync.Mutex<\/code> around both methods.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q67. What is a cache stampede (thundering herd) and how do you stop it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A cache stampede happens when a popular key expires and hundreds of requests miss the cache at the same moment. All of them hit the database together, which can overload it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are common fixes.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Request coalescing:<\/strong> only one request loads the value, and the others wait for its result. In Go, <code>golang.org\/x\/sync\/singleflight<\/code> does this.<\/li>\n\n\n<li><strong>Locking:<\/strong> the first request sets a short lock key in Redis, and others wait or serve old data.<\/li>\n\n\n<li><strong>Early refresh:<\/strong> refresh hot keys a little before they expire.<\/li>\n\n\n<li><strong>TTL jitter:<\/strong> spread expiry times so keys do not expire together.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here is how singleflight looks in a Go handler.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import \"golang.org\/x\/sync\/singleflight\"\n\nvar group singleflight.Group\n\nfunc getProduct(ctx context.Context, id string) (Product, error) {\n    \/\/ All callers with the same key share one database call.\n    v, err, _ := group.Do(\"product:\"+id, func() (any, error) {\n        return loadProductFromDB(ctx, id)\n    })\n    if err != nil {\n        return Product{}, err\n    }\n    return v.(Product), nil\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q68. What is cache penetration and how do you prevent it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Cache penetration happens when requests ask for keys that do not exist, for example <code>user:999999999<\/code>. The cache never has them, so every request goes to the database. Attackers can use this to overload you.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can cache the &#8220;not found&#8221; result for a short time, validate IDs early, or use a Bloom filter. A Bloom filter quickly tells you &#8220;this key surely does not exist&#8221;, so you skip the database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q69. What is a hot key problem in Redis?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A hot key is one key that gets a huge share of traffic, such as the score of a live cricket match. Even in a Redis cluster, one key lives on one node, so that node gets overloaded.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can fix it by caching the hot key locally in each Go pod for a second or two, or by copying it to several keys (<code>score:1<\/code>, <code>score:2<\/code>) and reading a random one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q70. What is Redis and what is it used for in system design?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Redis is an in-memory data store that is very fast and supports many data types, such as strings, hashes, lists, sets, sorted sets and streams. Teams use it for much more than caching.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Use case<\/th><th>Redis feature<\/th><\/tr><\/thead><tbody><tr><td>Cache<\/td><td>Strings with TTL<\/td><\/tr><tr><td>Sessions<\/td><td>Hashes with TTL<\/td><\/tr><tr><td>Rate limiting<\/td><td><code>INCR<\/code> with expiry, or sorted sets<\/td><\/tr><tr><td>Leaderboards<\/td><td>Sorted sets<\/td><\/tr><tr><td>Simple queues<\/td><td>Lists or streams<\/td><\/tr><tr><td>Distributed locks<\/td><td><code>SET key value NX PX 30000<\/code><\/td><\/tr><tr><td>Pub\/sub messages<\/td><td>Pub\/sub channels<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In Go, the most used client is <code>github.com\/redis\/go-redis<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">System Design Interview Questions on Queues, Events and Async Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Not every job must finish while the user waits. So this group of system design interview questions covers message queues, events and how services work together without calling each other directly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q71. What is a message queue and why do we use it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A message queue holds messages from a producer until a consumer is ready to process them. The producer does not wait for the work to finish. For example, after a user places an order, the API puts an &#8220;order placed&#8221; message in a queue and answers at once. Then a worker sends the email and updates stock later.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Queues help in three ways.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Faster responses:<\/strong> slow work moves to the background.<\/li>\n\n\n<li><strong>Decoupling:<\/strong> the producer does not need to know who consumes the message.<\/li>\n\n\n<li><strong>Smoothing spikes:<\/strong> a burst of 10,000 orders waits in the queue, and workers process them at a steady pace.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q72. What is the difference between a message queue and pub\/sub?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In a queue, each message goes to one consumer, even if many consumers are listening. It works like tasks on a to-do board, where once someone takes a task, nobody else does it. In pub\/sub (publish and subscribe), each message goes to every subscriber, like a WhatsApp group message.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So use a queue to share work between workers. Use pub\/sub when several services must all react to the same event, for example email, analytics and stock services all reacting to &#8220;order placed&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q73. What is the difference between Kafka, RabbitMQ and Amazon SQS?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">All three move messages, but they are built for different jobs.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Kafka<\/th><th>RabbitMQ<\/th><th>Amazon SQS<\/th><\/tr><\/thead><tbody><tr><td>Model<\/td><td>Distributed log<\/td><td>Message broker with queues<\/td><td>Managed queue<\/td><\/tr><tr><td>Messages after reading<\/td><td>Kept for a set time<\/td><td>Removed after ack<\/td><td>Removed after delete<\/td><\/tr><tr><td>Replay old messages<\/td><td>Yes<\/td><td>No (except streams)<\/td><td>No<\/td><\/tr><tr><td>Ordering<\/td><td>Per partition<\/td><td>Per queue<\/td><td>FIFO queues only<\/td><\/tr><tr><td>Throughput<\/td><td>Very high<\/td><td>High<\/td><td>High, fully managed<\/td><\/tr><tr><td>Best for<\/td><td>Event streaming, logs, analytics<\/td><td>Task queues, complex routing<\/td><td>Simple queues on AWS<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So pick Kafka for high-volume event streams and replay. Pick RabbitMQ for flexible routing of tasks. Pick SQS when you are on AWS and want no servers to manage.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q74. What are Kafka topics, partitions and consumer groups?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A topic is a named stream of messages, such as <code>orders<\/code>. Each topic is split into partitions, and each partition is an ordered log stored on brokers. The message key decides the partition, so all messages for <code>order-42<\/code> land in the same partition and stay in order.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A consumer group is a set of consumers sharing the work. Each partition goes to only one consumer in the group. So if a topic has 6 partitions, up to 6 consumers in one group can read in parallel, and a seventh would sit idle.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q75. What are at-most-once, at-least-once and exactly-once delivery?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These describe how many times a message can be processed.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>At-most-once:<\/strong> a message is processed zero or one time. It may be lost, but never repeated.<\/li>\n\n\n<li><strong>At-least-once:<\/strong> a message is never lost, but it may be processed more than once. This is the most common setting.<\/li>\n\n\n<li><strong>Exactly-once:<\/strong> each message has its effect one time. True exactly-once is hard across systems, and Kafka offers it only inside Kafka with transactions.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So in practice, use at-least-once delivery with idempotent consumers. For example, the consumer saves the message ID and skips it if it has already processed it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q76. What is the outbox pattern?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The outbox pattern solves the &#8220;dual write&#8221; problem. Imagine your Go service saves an order in PostgreSQL and then publishes an event to Kafka. If the service crashes between the two steps, the database has the order but no event was sent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the outbox pattern, you write the order and an event row into an <code>outbox<\/code> table in the same database transaction. Then a separate relay process reads new outbox rows and publishes them to Kafka. So either both happen or neither does.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tx, err := db.BeginTx(ctx, nil)\nif err != nil {\n    return err\n}\ndefer tx.Rollback() \/\/ safe to call; does nothing after Commit\n\n_, err = tx.ExecContext(ctx,\n    `INSERT INTO orders (id, user_id, total) VALUES ($1, $2, $3)`,\n    order.ID, order.UserID, order.Total)\nif err != nil {\n    return err\n}\n\n\/\/ Same transaction, so the event is saved only if the order is saved.\n_, err = tx.ExecContext(ctx,\n    `INSERT INTO outbox (id, topic, payload) VALUES ($1, $2, $3)`,\n    eventID, \"orders\", payload)\nif err != nil {\n    return err\n}\nreturn tx.Commit()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q77. What is a dead letter queue?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A dead letter queue (DLQ) is a separate queue for messages that keep failing. For example, after 5 failed tries, the message moves to the DLQ instead of blocking the main queue forever. Then engineers can inspect it, fix the bug and replay it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Without a DLQ, one bad message (a &#8220;poison message&#8221;) can stop a consumer or loop forever.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q78. What is backpressure?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Backpressure is a way for a slow part of the system to tell a fast part to slow down. Without it, the fast producer fills memory or queues until something crashes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Go, a buffered channel gives you backpressure for free. When the buffer is full, the sender blocks until a worker takes an item. At the system level, you can reject requests with HTTP 429 or 503, limit queue size or scale workers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q79. How do you build a worker pool in Go for background jobs?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A worker pool starts a fixed number of goroutines that read jobs from a channel. So you control how much work runs at the same time, and you do not start one goroutine per job without limit.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"sort\"\n    \"sync\"\n)\n\nfunc main() {\n    jobs := make(chan int, 10)    \/\/ job queue\n    results := make(chan string, 10)\n    var wg sync.WaitGroup\n\n    \/\/ Start 3 workers.\n    for w := 1; w &lt;= 3; w++ {\n        wg.Add(1)\n        go func(worker int) {\n            defer wg.Done()\n            for orderID := range jobs {\n                results &lt;- fmt.Sprintf(\"order %d emailed\", orderID)\n            }\n        }(w)\n    }\n\n    \/\/ Send 5 jobs, then close the channel so workers stop.\n    for id := 101; id &lt;= 105; id++ {\n        jobs &lt;- id\n    }\n    close(jobs)\n\n    wg.Wait()\n    close(results)\n\n    \/\/ Workers finish in random order, so sort before printing.\n    var lines []string\n    for r := range results {\n        lines = append(lines, r)\n    }\n    sort.Strings(lines)\n    for _, line := range lines {\n        fmt.Println(line)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>order 101 emailed\norder 102 emailed\norder 103 emailed\norder 104 emailed\norder 105 emailed<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The closed <code>jobs<\/code> channel is the signal for workers to exit. For more patterns like this, see our <a href=\"https:\/\/smitabharat.com\/blog\/go-goroutine-programs\/\">Go goroutine programs<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q80. How do you keep message order in a distributed system?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Global ordering across a whole system is slow and rarely needed. Usually you only need order per entity, for example all events for one order or one user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So you use a partition key. In Kafka, every message with key <code>order-42<\/code> goes to the same partition, and one consumer reads that partition in order. Also, consumers should process one partition&#8217;s messages one by one, or check a version number before applying an update.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q81. What is an event-driven architecture?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In an event-driven architecture, services publish events about things that happened, such as <code>OrderPlaced<\/code> or <code>PaymentFailed<\/code>. Other services subscribe and react in their own time. The publisher does not know or care who listens.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This makes it easy to add new features. For example, a new loyalty points service can subscribe to <code>OrderPlaced<\/code> without any change to the order service. However, the flow is harder to follow, so you need good tracing and clear event contracts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q82. What is the saga pattern?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A saga handles a business transaction that spans several services, each with its own database. Since you cannot use one database transaction, the saga runs a series of local steps. If a step fails, it runs compensating actions to undo the earlier steps.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, an order saga reserves stock, then charges payment, then books delivery. If payment fails, it releases the stock. There are two styles.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Choreography:<\/strong> each service listens for events and decides the next step. It is simple for short flows.<\/li>\n\n\n<li><strong>Orchestration:<\/strong> one orchestrator service tells each service what to do. It is easier to follow for long flows.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q83. Why is two-phase commit rarely used in microservices?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Two-phase commit (2PC) asks all participants to &#8220;prepare&#8221; and then &#8220;commit&#8221; together. It gives strong consistency, but every service must wait and hold locks until the coordinator decides. If the coordinator fails at the wrong moment, participants can stay blocked.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So microservices usually prefer sagas with the outbox pattern. They accept eventual consistency in exchange for better availability.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q84. How do you schedule delayed or recurring jobs?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For recurring jobs, such as a nightly report, use a scheduler like a Kubernetes CronJob or a cloud scheduler. For delayed jobs, such as &#8220;send a reminder in 24 hours&#8221;, store the job with a <code>run_at<\/code> time in a database or a Redis sorted set, and let workers poll for jobs that are due.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When several instances run the scheduler, make sure only one runs each job. You can use a database row lock (<code>SELECT ... FOR UPDATE SKIP LOCKED<\/code>) or a leader election.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">System Design Interview Questions on Reliability and Fault Tolerance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every part of a system fails sooner or later. So these system design interview questions check how your Go service behaves when a database is slow, a network drops or traffic doubles.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q85. What is fault tolerance?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Fault tolerance is the ability of a system to keep working when some parts fail. For example, if one of three API servers crashes, the load balancer sends traffic to the other two, and users notice nothing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You build it with redundancy (more than one copy), timeouts, retries, circuit breakers and graceful degradation. The goal is that one failure never becomes a full outage.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q86. Why must every network call have a timeout?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Without a timeout, a call to a slow service can wait forever. Each waiting request holds a goroutine, memory and maybe a database connection. Soon your service runs out of resources, and the slowness spreads to everyone who calls you.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Go, the default <code>http.Client<\/code> has no timeout, which is a classic mistake. So always set one, and pass a <code>context<\/code> with a deadline.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>client := &amp;http.Client{Timeout: 3 * time.Second} \/\/ whole request limit\n\nctx, cancel := context.WithTimeout(r.Context(), 2*time.Second)\ndefer cancel()\n\nreq, err := http.NewRequestWithContext(ctx, http.MethodGet, \"http:\/\/inventory\/items\/42\", nil)\nif err != nil {\n    return err\n}\nresp, err := client.Do(req) \/\/ stops at whichever limit comes first<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Also, set timeouts on your own server, such as <code>ReadHeaderTimeout<\/code> and <code>WriteTimeout<\/code> on <code>http.Server<\/code>. See our <a href=\"https:\/\/smitabharat.com\/blog\/go-context-interview-questions-part-17\/\">Go context interview questions<\/a> for more on deadlines.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q87. How do you design safe retries?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Retries help with short failures, such as a brief network drop. However, careless retries make an outage worse, because every client hammers a struggling service at once. So follow these rules.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Retry only on temporary errors, such as timeouts, 503 or 429, never on 400 Bad Request.<\/li>\n\n\n<li>Retry only idempotent operations, or use an idempotency key.<\/li>\n\n\n<li>Use exponential backoff, so each wait is longer than the last.<\/li>\n\n\n<li>Add jitter (randomness), so clients do not retry at the same moment.<\/li>\n\n\n<li>Set a maximum number of tries and respect the request deadline.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a Go program that shows exponential backoff with a cap. Jitter is left out so the output is the same every time.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"errors\"\n    \"fmt\"\n    \"time\"\n)\n\nvar attempts int\n\n\/\/ callPaymentAPI fails twice, then works.\nfunc callPaymentAPI() error {\n    attempts++\n    if attempts &lt; 3 {\n        return errors.New(\"503 service unavailable\")\n    }\n    return nil\n}\n\nfunc main() {\n    base := 100 * time.Millisecond\n    maxWait := 1 * time.Second\n\n    for try := 1; try &lt;= 5; try++ {\n        err := callPaymentAPI()\n        if err == nil {\n            fmt.Println(\"try\", try, \"succeeded\")\n            return\n        }\n        \/\/ Wait 100ms, 200ms, 400ms ... but never more than maxWait.\n        wait := base &lt;&lt; (try - 1)\n        if wait &gt; maxWait {\n            wait = maxWait\n        }\n        fmt.Printf(\"try %d failed (%v), waiting %v\\n\", try, err, wait)\n        \/\/ In real code: time.Sleep(wait + random jitter), and stop if ctx is done.\n    }\n    fmt.Println(\"giving up\")\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>try 1 failed (503 service unavailable), waiting 100ms\ntry 2 failed (503 service unavailable), waiting 200ms\ntry 3 succeeded<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q88. What is a circuit breaker?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A circuit breaker stops calling a service that keeps failing, so you fail fast instead of waiting on timeouts. It works like the electrical breaker in your house, which cuts power when something is wrong.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It has three states.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Closed:<\/strong> calls go through normally, and failures are counted.<\/li>\n\n\n<li><strong>Open:<\/strong> after too many failures, calls fail at once without reaching the service.<\/li>\n\n\n<li><strong>Half-open:<\/strong> after a cool-down time, a few test calls go through. If they work, the breaker closes again.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a simple circuit breaker in Go.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"errors\"\n    \"fmt\"\n)\n\ntype Breaker struct {\n    state       string \/\/ \"closed\", \"open\" or \"half-open\"\n    failures    int\n    maxFailures int\n}\n\nvar ErrOpen = errors.New(\"circuit open, failing fast\")\n\nfunc (b *Breaker) Call(fn func() error) error {\n    if b.state == \"open\" {\n        return ErrOpen\n    }\n    err := fn()\n    if err != nil {\n        b.failures++\n        if b.state == \"half-open\" || b.failures &gt;= b.maxFailures {\n            b.state = \"open\"\n        }\n        return err\n    }\n    b.failures = 0\n    b.state = \"closed\" \/\/ success closes the breaker\n    return nil\n}\n\n\/\/ CoolDownPassed is called by a timer in real code.\nfunc (b *Breaker) CoolDownPassed() { b.state = \"half-open\" }\n\nfunc main() {\n    b := &amp;Breaker{state: \"closed\", maxFailures: 3}\n    failing := func() error { return errors.New(\"timeout\") }\n    working := func() error { return nil }\n\n    for i := 1; i &lt;= 4; i++ {\n        err := b.Call(failing)\n        fmt.Printf(\"call %d: %v (state: %s)\\n\", i, err, b.state)\n    }\n    b.CoolDownPassed()\n    err := b.Call(working)\n    fmt.Printf(\"test call: %v (state: %s)\\n\", err, b.state)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>call 1: timeout (state: closed)\ncall 2: timeout (state: closed)\ncall 3: timeout (state: open)\ncall 4: circuit open, failing fast (state: open)\ntest call: &lt;nil&gt; (state: closed)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In production, add a mutex and a real timer, or use a tested library such as <code>github.com\/sony\/gobreaker<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q89. What is the bulkhead pattern?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The bulkhead pattern splits resources into separate pools, so one failing part cannot use up everything. The name comes from ships, which have walls inside the hull so one leak does not sink the whole ship.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, give the payment client its own pool of 20 connections and the recommendation client another 20. If recommendations get slow, payments still work. In Go, a buffered channel used as a semaphore limits how many goroutines call each dependency.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q90. What is rate limiting and which algorithms do you know?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Rate limiting caps how many requests a client can make in a time window, for example 100 requests per minute per API key. It protects your service from abuse and from one noisy customer.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Algorithm<\/th><th>How it works<\/th><th>Note<\/th><\/tr><\/thead><tbody><tr><td>Fixed window<\/td><td>Count requests per minute, reset each minute<\/td><td>Simple, allows bursts at the edges<\/td><\/tr><tr><td>Sliding window log<\/td><td>Keep a timestamp per request<\/td><td>Exact, uses more memory<\/td><\/tr><tr><td>Sliding window counter<\/td><td>Mix of current and previous window counts<\/td><td>Good balance<\/td><\/tr><tr><td>Token bucket<\/td><td>Tokens refill at a fixed rate, each request uses one<\/td><td>Allows short bursts, very common<\/td><\/tr><tr><td>Leaky bucket<\/td><td>Requests leave at a fixed rate<\/td><td>Smooth output<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Go has a token bucket in <code>golang.org\/x\/time\/rate<\/code>. For many servers, keep the counters in Redis, so every instance shares the same limit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q91. How do you build a token bucket rate limiter in Go?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A token bucket holds up to a set number of tokens. Each request takes one token, and tokens refill at a steady rate. If the bucket is empty, the request is rejected with HTTP 429. This version takes the current time as an input, so the example is easy to test.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\ntype TokenBucket struct {\n    capacity   float64\n    tokens     float64\n    refillRate float64 \/\/ tokens per second\n    last       time.Time\n}\n\nfunc (b *TokenBucket) Allow(now time.Time) bool {\n    \/\/ Add tokens for the time that passed, up to the capacity.\n    elapsed := now.Sub(b.last).Seconds()\n    b.tokens = min(b.capacity, b.tokens+elapsed*b.refillRate)\n    b.last = now\n\n    if b.tokens &gt;= 1 {\n        b.tokens--\n        return true\n    }\n    return false\n}\n\nfunc main() {\n    start := time.Date(2026, 1, 1, 10, 0, 0, 0, time.UTC)\n    bucket := &amp;TokenBucket{capacity: 3, tokens: 3, refillRate: 1, last: start}\n\n    \/\/ 5 requests at the same moment: only 3 pass.\n    for i := 1; i &lt;= 5; i++ {\n        fmt.Printf(\"request %d allowed: %v\\n\", i, bucket.Allow(start))\n    }\n    \/\/ 2 seconds later, 2 tokens have refilled.\n    later := start.Add(2 * time.Second)\n    for i := 6; i &lt;= 8; i++ {\n        fmt.Printf(\"request %d allowed: %v\\n\", i, bucket.Allow(later))\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>request 1 allowed: true\nrequest 2 allowed: true\nrequest 3 allowed: true\nrequest 4 allowed: false\nrequest 5 allowed: false\nrequest 6 allowed: true\nrequest 7 allowed: true\nrequest 8 allowed: false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The built-in <code>min<\/code> function was added in Go 1.21. In a real server, keep one bucket per user or API key, and guard it with a mutex.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q92. What is graceful degradation?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Graceful degradation means the system keeps its main feature working when a less important part fails. For example, if the recommendation service is down, the shop page still loads, just without the &#8220;You may also like&#8221; box.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To do this, mark each dependency as critical or optional. For optional ones, use short timeouts, a circuit breaker and a fallback, such as cached or default data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q93. What is load shedding?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Load shedding means rejecting some requests on purpose when the system is overloaded, so the rest still succeed. It is better to answer 80% of users quickly than to answer 100% so slowly that everyone times out.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, a Go service can track in-flight requests and return 503 when the count goes above a limit. You can also drop low-priority traffic first, such as analytics, before checkout requests.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q94. How do you shut down a Go service gracefully?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">During a deploy, Kubernetes sends SIGTERM to your pod. A graceful shutdown stops accepting new requests, lets current requests finish and then closes database and queue connections. Otherwise, users get errors on every deploy.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func main() {\n    srv := &amp;http.Server{Addr: \":8080\", Handler: routes()}\n\n    \/\/ Stop when SIGINT or SIGTERM arrives.\n    ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)\n    defer stop()\n\n    go func() {\n        if err := srv.ListenAndServe(); err != nil &amp;&amp; !errors.Is(err, http.ErrServerClosed) {\n            log.Fatal(err)\n        }\n    }()\n\n    &lt;-ctx.Done() \/\/ wait for the signal\n    log.Println(\"shutting down\")\n\n    \/\/ Give in-flight requests up to 20 seconds to finish.\n    shutdownCtx, cancel := context.WithTimeout(context.Background(), 20*time.Second)\n    defer cancel()\n    if err := srv.Shutdown(shutdownCtx); err != nil {\n        log.Println(\"forced shutdown:\", err)\n    }\n    db.Close()\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure the shutdown time fits inside the pod&#8217;s <code>terminationGracePeriodSeconds<\/code>, which is 30 seconds by default.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q95. What is the difference between liveness and readiness probes?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Both are health checks in Kubernetes, but they lead to different actions.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Probe<\/th><th>Question it answers<\/th><th>What happens on failure<\/th><\/tr><\/thead><tbody><tr><td>Liveness<\/td><td>Is the process stuck or dead?<\/td><td>Kubernetes restarts the container<\/td><\/tr><tr><td>Readiness<\/td><td>Can it take traffic right now?<\/td><td>Pod is removed from the Service until ready<\/td><\/tr><tr><td>Startup<\/td><td>Has the app finished starting?<\/td><td>Other probes wait until it passes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So a readiness check can verify the database connection, but a liveness check should stay simple. If liveness checked the database, a short database outage would restart every pod at once.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q96. What is the difference between active-passive and active-active failover?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In active-passive, one server or region handles all traffic, and a standby waits to take over if it fails. It is simpler, but the standby sits idle and failover takes some time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In active-active, all servers or regions handle traffic at the same time. If one fails, the others take its share. It uses resources better and fails over faster. However, it is harder when several regions accept writes to the same data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q97. How do you design a multi-region system?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A multi-region design runs your service in two or more cloud regions. It protects against a full region outage and gives lower latency to users far apart.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are the main decisions.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Traffic:<\/strong> use geo DNS or a global load balancer to send users to the nearest healthy region.<\/li>\n\n\n<li><strong>Data:<\/strong> decide if one region takes writes (simpler) or every region does (needs conflict handling).<\/li>\n\n\n<li><strong>Replication:<\/strong> copy data between regions, usually asynchronously.<\/li>\n\n\n<li><strong>Failover:<\/strong> test it often, because a failover you never practised will probably fail.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q98. What is chaos engineering?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Chaos engineering means breaking things on purpose in a controlled way to check that the system survives. For example, you kill a random pod, add 500 ms of network delay or block access to Redis, then watch what happens.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It finds weak spots before real outages do. Start small in a staging environment, and only move to production when you have good monitoring and a quick way to stop the test.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">System Design Interview Questions on Observability and Security<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A design is not finished until you can see what it is doing and keep bad actors out. So these system design interview questions cover monitoring, tracing, authentication and data safety.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q99. What is observability, and what are its three pillars?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Observability is how well you can understand what is happening inside a system by looking at its outputs. The three pillars are logs, metrics and traces.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Pillar<\/th><th>What it is<\/th><th>Example question it answers<\/th><\/tr><\/thead><tbody><tr><td>Logs<\/td><td>Text records of single events<\/td><td>Why did order 42 fail?<\/td><\/tr><tr><td>Metrics<\/td><td>Numbers over time<\/td><td>How many 500 errors per minute?<\/td><\/tr><tr><td>Traces<\/td><td>The path of one request across services<\/td><td>Which service made checkout slow?<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So metrics tell you something is wrong, traces show where, and logs explain why.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q100. What is structured logging, and how do you do it in Go?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Structured logging writes logs as key-value pairs, usually JSON, instead of free text. So tools like Loki, Elasticsearch or CloudWatch can search and filter by fields such as <code>user_id<\/code> or <code>status<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since Go 1.21, the standard library has <code>log\/slog<\/code> for this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"log\/slog\"\n    \"os\"\n)\n\nfunc main() {\n    \/\/ Remove the time field so this example prints the same output every run.\n    opts := &amp;slog.HandlerOptions{\n        ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {\n            if a.Key == slog.TimeKey {\n                return slog.Attr{}\n            }\n            return a\n        },\n    }\n    logger := slog.New(slog.NewJSONHandler(os.Stdout, opts))\n\n    logger.Info(\"order placed\", \"order_id\", 42, \"user_id\", 7, \"total\", 499.5)\n    logger.Error(\"payment failed\", \"order_id\", 43, \"reason\", \"card declined\")\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>{\"level\":\"INFO\",\"msg\":\"order placed\",\"order_id\":42,\"user_id\":7,\"total\":499.5}\n{\"level\":\"ERROR\",\"msg\":\"payment failed\",\"order_id\":43,\"reason\":\"card declined\"}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In real services, keep the time field and add a request ID or trace ID to every log line.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q101. What metrics should a backend service track?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A simple and popular set is the four golden signals from Google&#8217;s SRE book.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Latency:<\/strong> how long requests take, as p50, p95 and p99.<\/li>\n\n\n<li><strong>Traffic:<\/strong> requests per second.<\/li>\n\n\n<li><strong>Errors:<\/strong> the rate of failed requests, such as 5xx responses.<\/li>\n\n\n<li><strong>Saturation:<\/strong> how full your resources are, such as CPU, memory, connection pools and queue length.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For Go services, also watch goroutine count, heap size and GC pause time. Prometheus with Grafana is a common setup, and the Prometheus Go client exposes runtime metrics for you.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q102. What is distributed tracing?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Distributed tracing follows one request as it moves through many services. Each step is a span with a start time and duration, and all spans share one trace ID. So you can see a timeline like &#8220;gateway 5 ms, order service 30 ms, payment service 400 ms&#8221; and spot the slow part at once.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Go, OpenTelemetry is the standard way to add tracing. The trace ID travels inside <code>context.Context<\/code> within a service, and in HTTP headers (the W3C <code>traceparent<\/code> header) between services.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q103. How do you set up good alerts?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alert on symptoms that users feel, such as a high error rate or slow p99 latency, not on every CPU spike. Each alert should need a human action and link to a runbook that says what to check first.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Too many alerts cause alert fatigue, and people start to ignore them. So review noisy alerts often, and use SLO-based alerts that fire when you burn the error budget too fast.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q104. What is the difference between authentication and authorization?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Authentication (AuthN) checks who you are, for example by password, OTP or a login with Google. Authorization (AuthZ) checks what you are allowed to do, for example &#8220;only admins can delete users&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So authentication comes first and answers &#8220;who?&#8221;. Authorization comes next and answers &#8220;can they?&#8221;. A 401 status means not authenticated, and 403 means authenticated but not allowed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q105. What is the difference between session-based auth and token-based auth (JWT)?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With sessions, the server stores session data, usually in Redis, and gives the browser a session ID cookie. With JWT, the server gives the client a signed token that holds the user&#8217;s claims, and any service can verify it without a database lookup.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Sessions<\/th><th>JWT<\/th><\/tr><\/thead><tbody><tr><td>State stored<\/td><td>On the server (Redis)<\/td><td>Inside the token<\/td><\/tr><tr><td>Logout<\/td><td>Easy, delete the session<\/td><td>Hard, the token is valid until expiry<\/td><\/tr><tr><td>Scaling<\/td><td>Needs a shared store<\/td><td>Any service can verify<\/td><\/tr><tr><td>Size<\/td><td>Small cookie<\/td><td>Larger token on every request<\/td><\/tr><tr><td>Best for<\/td><td>Web apps<\/td><td>APIs and microservices<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So if you use JWT, keep access tokens short-lived, for example 15 minutes, and use refresh tokens to get new ones.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q106. What is OAuth 2.0 and OpenID Connect?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">OAuth 2.0 is a standard for giving an app limited access to a user&#8217;s data without sharing the password. For example, a photo app gets permission to read your Google Photos. OpenID Connect (OIDC) is built on top of OAuth 2.0 and adds login, so the app also learns who you are through an ID token.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For web and mobile apps, use the Authorization Code flow with PKCE. In Go, the <code>golang.org\/x\/oauth2<\/code> package handles the OAuth flow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q107. How do you secure communication between microservices?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use TLS for all traffic, even inside your own network, because you should not trust the internal network blindly. Mutual TLS (mTLS) goes one step further, because both sides show a certificate, so each service proves who it is.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, pass the user&#8217;s identity in a signed token, and check permissions in each service. A service mesh can handle mTLS automatically, so your Go code does not need to manage certificates.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q108. How do you store secrets such as database passwords and API keys?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Never put secrets in your code or Git repository. Instead, use a secret manager such as HashiCorp Vault, AWS Secrets Manager or Kubernetes Secrets with encryption turned on. The app reads secrets at startup from environment variables or mounted files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, give each service only the secrets it needs, rotate them regularly and never print them in logs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q109. How do you protect user data in a system design?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Protect data in three places.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>In transit:<\/strong> use HTTPS and TLS everywhere.<\/li>\n\n\n<li><strong>At rest:<\/strong> encrypt databases, disks and backups.<\/li>\n\n\n<li><strong>In use:<\/strong> limit who can read data, mask personal data in logs and keep audit logs of access.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For passwords, never store plain text or a fast hash. Use a slow hashing algorithm such as bcrypt or Argon2. In Go, <code>golang.org\/x\/crypto\/bcrypt<\/code> makes this easy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q110. What are the most common web security risks to plan for?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The OWASP Top 10 list is the usual reference. In a design interview, mention the ones that affect your design most.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Broken access control:<\/strong> users reading other users&#8217; data by changing an ID in the URL.<\/li>\n\n\n<li><strong>Injection:<\/strong> SQL injection. In Go, always use placeholders like <code>$1<\/code> with <code>database\/sql<\/code>, never string concatenation.<\/li>\n\n\n<li><strong>Broken authentication:<\/strong> weak passwords, no rate limit on login, long-lived tokens.<\/li>\n\n\n<li><strong>Security misconfiguration:<\/strong> open admin panels, default passwords, debug endpoints in production.<\/li>\n\n\n<li><strong>Vulnerable dependencies:<\/strong> run <code>govulncheck<\/code> in CI to find known issues in your Go modules.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Our <a href=\"https:\/\/smitabharat.com\/blog\/go-security-scenario-questions\/\">Go security scenario questions<\/a> cover these with real cases.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">System Design Interview Questions for Go Developers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These system design interview questions are special to Go roles. Interviewers want to see how Go features shape the way you build and run a service.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q111. Why is Go a good choice for backend and distributed systems?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go was built at Google for networked servers, so it fits system design well.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Cheap concurrency:<\/strong> goroutines start with a small stack of a few kilobytes, so one service can handle many thousands of connections.<\/li>\n\n\n<li><strong>Fast and simple:<\/strong> compiled native code with a small, readable language.<\/li>\n\n\n<li><strong>Small deployments:<\/strong> one static binary, which makes tiny Docker images.<\/li>\n\n\n<li><strong>Strong standard library:<\/strong> <code>net\/http<\/code>, <code>encoding\/json<\/code>, <code>context<\/code>, <code>database\/sql<\/code> and <code>log\/slog<\/code> are built in.<\/li>\n\n\n<li><strong>Proven:<\/strong> Docker, Kubernetes, etcd, Prometheus and Terraform are written in Go.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q112. How do you structure a Go microservice project?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There is no single official layout, but this simple shape is common and easy to explain.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>order-service\/\n  cmd\/\n    order-api\/\n      main.go          \/\/ wiring: config, DB, routes, start server\n  internal\/\n    order\/\n      handler.go       \/\/ HTTP layer: decode request, call service\n      service.go       \/\/ business rules\n      repository.go    \/\/ database access\n      model.go         \/\/ Order struct\n    platform\/\n      postgres\/        \/\/ DB connection helpers\n      kafka\/           \/\/ producer and consumer helpers\n  migrations\/          \/\/ SQL migration files\n  go.mod\n  Dockerfile<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>internal<\/code> folder stops other modules from importing your code, so you can change it freely. Keep <code>main.go<\/code> small, because it should only connect the pieces. Our <a href=\"https:\/\/smitabharat.com\/blog\/go-dependencies-go-mod-go-sum\/\">Go dependencies post<\/a> explains <code>go.mod<\/code> and modules.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q113. What is clean architecture in Go?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Clean architecture keeps business rules in the centre and pushes details like HTTP, databases and queues to the edges. The inner layers do not import the outer ones. Instead, the service layer defines small interfaces, and the outer layers implement them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So you can swap PostgreSQL for another database, or test the service with a fake repository, without touching business code. However, do not overdo it. A small service does not need five layers and twenty interfaces.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q114. How do you use interfaces and dependency injection in Go services?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Go, you inject dependencies by passing them into a constructor, usually as small interfaces. A common Go rule is &#8220;accept interfaces, return structs&#8221;. Define the interface where it is used, not where it is implemented.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"errors\"\n    \"fmt\"\n)\n\n\/\/ The service only needs these two methods, so the interface is small.\ntype OrderStore interface {\n    Save(id string, total int) error\n    Count() int\n}\n\ntype OrderService struct {\n    store OrderStore \/\/ injected dependency\n}\n\nfunc NewOrderService(store OrderStore) *OrderService {\n    return &amp;OrderService{store: store}\n}\n\nfunc (s *OrderService) PlaceOrder(id string, total int) error {\n    if total &lt;= 0 {\n        return errors.New(\"total must be positive\")\n    }\n    return s.store.Save(id, total)\n}\n\n\/\/ memoryStore is a fake used in tests; production would use PostgreSQL.\ntype memoryStore struct{ orders map[string]int }\n\nfunc (m *memoryStore) Save(id string, total int) error { m.orders[id] = total; return nil }\nfunc (m *memoryStore) Count() int                      { return len(m.orders) }\n\nfunc main() {\n    store := &amp;memoryStore{orders: map[string]int{}}\n    svc := NewOrderService(store)\n\n    fmt.Println(svc.PlaceOrder(\"A1\", 500))\n    fmt.Println(svc.PlaceOrder(\"A2\", 0))\n    fmt.Println(\"orders saved:\", store.Count())\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;nil&gt;\ntotal must be positive\norders saved: 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Most Go teams wire dependencies by hand in <code>main.go<\/code>. Tools like Wire or Fx exist, but manual wiring is clear and often enough.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q115. How does context.Context help in a distributed system?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>context.Context<\/code> carries three things through a request: a deadline or timeout, a cancel signal and request-scoped values such as a trace ID. When a user closes the browser, the HTTP server cancels the request context. Then every database query and outgoing call that uses that context stops too.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So pass <code>ctx<\/code> as the first parameter of every function that does I\/O. This one habit stops wasted work across many services.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q116. How do you call several services at the same time and handle errors?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>errgroup<\/code> from <code>golang.org\/x\/sync\/errgroup<\/code>. It starts goroutines, waits for all of them and returns the first error. With <code>errgroup.WithContext<\/code>, the first failure also cancels the others.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>g, ctx := errgroup.WithContext(r.Context())\n\nvar user User\nvar orders []Order\n\ng.Go(func() error {\n    var err error\n    user, err = userClient.Get(ctx, userID)\n    return err\n})\ng.Go(func() error {\n    var err error\n    orders, err = orderClient.List(ctx, userID)\n    return err\n})\n\nif err := g.Wait(); err != nil {\n    return err \/\/ one call failed, and the other was cancelled\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So a page that needs data from three services takes as long as the slowest call, not the sum of all three. You can also call <code>g.SetLimit(n)<\/code> to cap how many run at once.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q117. What is a goroutine leak, and how do you prevent it in a long-running service?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A goroutine leak happens when a goroutine never exits, for example because it waits forever on a channel nobody writes to. In a server that runs for weeks, leaks grow slowly until memory runs out.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To prevent leaks, make sure every goroutine has a clear way to stop, such as a closed channel or a cancelled context. Watch the goroutine count metric, and in tests use <code>go.uber.org\/goleak<\/code>. Our <a href=\"https:\/\/smitabharat.com\/blog\/go-goroutines-interview-questions-part-14\/\">Go goroutines interview questions<\/a> explain this further.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q118. How do you limit concurrency in Go?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Starting a goroutine per item is easy, but 100,000 goroutines all calling a database will overload it. So limit how many run at once.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Worker pool:<\/strong> a fixed number of goroutines reading from a jobs channel.<\/li>\n\n\n<li><strong>Semaphore:<\/strong> a buffered channel <code>make(chan struct{}, 10)<\/code>, where each goroutine sends before work and receives after.<\/li>\n\n\n<li><strong>errgroup with SetLimit:<\/strong> caps goroutines and collects errors.<\/li>\n\n\n<li><strong>golang.org\/x\/sync\/semaphore:<\/strong> a weighted semaphore for mixed job sizes.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q119. How do GOMAXPROCS and GOMEMLIMIT matter when Go runs in containers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>GOMAXPROCS<\/code> sets how many OS threads run Go code at the same time. Since Go 1.25, the runtime on Linux reads the container&#8217;s CPU limit and sets <code>GOMAXPROCS<\/code> to match. Before that, a pod limited to 2 CPUs on a 64-core node could start with 64, which caused heavy CPU throttling.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>GOMEMLIMIT<\/code> (since Go 1.19) gives the garbage collector a soft memory limit. So if a pod has a 1 GiB limit, setting <code>GOMEMLIMIT<\/code> to about 900MiB makes the GC work harder before the container gets killed for using too much memory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q120. How do you find performance problems in a Go service?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Measure first, then fix. Go has strong built-in tools.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Tool<\/th><th>What it shows<\/th><\/tr><\/thead><tbody><tr><td><code>net\/http\/pprof<\/code><\/td><td>CPU, heap, goroutine and block profiles from a live service<\/td><\/tr><tr><td><code>go test -bench<\/code><\/td><td>Speed and allocations of a function<\/td><\/tr><tr><td><code>go tool trace<\/code><\/td><td>Scheduler, GC and goroutine timeline<\/td><\/tr><tr><td>Race detector (<code>-race<\/code>)<\/td><td>Data races in tests<\/td><\/tr><tr><td>Metrics and traces<\/td><td>Which endpoint or dependency is slow<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Common fixes include reducing allocations, reusing buffers with <code>sync.Pool<\/code>, adding indexes, caching and batching database calls. See our <a href=\"https:\/\/smitabharat.com\/blog\/go-performance-interview-questions-part-23\/\">Go performance interview questions<\/a> for more.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q121. How do you manage configuration in a Go service?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Follow the twelve-factor idea: keep config in the environment, not in code. Read values from environment variables or a mounted file at startup, check them and fail fast if a required value is missing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Put all config in one struct and pass it to the parts that need it. So it is easy to see every setting in one place, and tests can build their own config.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q122. How do you design a Go service for zero-downtime deployments?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Several parts work together.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Rolling updates:<\/strong> Kubernetes replaces pods a few at a time.<\/li>\n\n\n<li><strong>Readiness probes:<\/strong> new pods get traffic only when ready.<\/li>\n\n\n<li><strong>Graceful shutdown:<\/strong> old pods finish in-flight requests on SIGTERM.<\/li>\n\n\n<li><strong>Backward-compatible changes:<\/strong> new code works with the old database schema, and old code works with the new one.<\/li>\n\n\n<li><strong>Expand and contract migrations:<\/strong> add new columns first, move data, then remove old columns in a later release.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You can add canary or blue-green releases for risky changes. Our <a href=\"https:\/\/smitabharat.com\/blog\/ci-cd-interview-questions\/\">CI\/CD interview questions<\/a> cover these release methods.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q123. How do you test a distributed Go system?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use several layers of tests.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Unit tests:<\/strong> business logic with fake dependencies, using table-driven tests.<\/li>\n\n\n<li><strong>Integration tests:<\/strong> real PostgreSQL or Redis in Docker, for example with Testcontainers.<\/li>\n\n\n<li><strong>Contract tests:<\/strong> check that services agree on API and event formats.<\/li>\n\n\n<li><strong>End-to-end tests:<\/strong> a few key user flows in a staging environment.<\/li>\n\n\n<li><strong>Load tests:<\/strong> tools like k6 or vegeta to find limits before users do.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Always run tests with <code>-race<\/code> in CI, because concurrency bugs are common in Go services.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q124. How would you build a simple distributed lock, and what are the risks?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A distributed lock makes sure only one instance does a job at a time, such as a nightly billing run. A simple way is Redis: <code>SET lock:billing &lt;unique-id&gt; NX PX 30000<\/code> sets the key only if it is free, with a 30-second expiry. To release, delete the key only if it still holds your unique ID, using a small Lua script.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, locks with expiry are risky. If your process pauses longer than the expiry, another instance takes the lock and both run. So make the job itself safe to repeat, or use a fencing token, a number that increases with each lock, which the database checks before accepting writes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">System Design Interview Questions: Classic Design Problems<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These are the full &#8220;design X&#8221; system design interview questions. For each one, the answer shows the main requirements, the key parts and the tricky points interviewers look for. Use the step-by-step method from the next section to present them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q125. How would you design a URL shortener like bit.ly?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The service turns a long URL into a short code, such as <code>sho.rt\/aZ3k9<\/code>, and redirects anyone who opens it. Reads are far more common than writes, often 100 to 1.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are the main parts.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>API:<\/strong> <code>POST \/urls<\/code> creates a short code, and <code>GET \/{code}<\/code> returns a 301 or 302 redirect.<\/li>\n\n\n<li><strong>Code generation:<\/strong> take a unique number from a counter or ID generator and encode it in base62 (a to z, A to Z, 0 to 9). Seven base62 characters give over 3.5 trillion codes.<\/li>\n\n\n<li><strong>Storage:<\/strong> a key-value table of <code>code -&gt; long_url, created_at, expires_at<\/code>.<\/li>\n\n\n<li><strong>Cache:<\/strong> keep popular codes in Redis, because a few links get most of the clicks.<\/li>\n\n\n<li><strong>Analytics:<\/strong> send click events to a queue, so the redirect stays fast.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here is base62 encoding in Go.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nconst alphabet = \"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n\n\/\/ toBase62 turns a number into a short code.\nfunc toBase62(n uint64) string {\n    if n == 0 {\n        return \"0\"\n    }\n    var code []byte\n    for n &gt; 0 {\n        code = append([]byte{alphabet[n%62]}, code...) \/\/ add the next digit at the front\n        n \/= 62\n    }\n    return string(code)\n}\n\nfunc main() {\n    for _, id := range []uint64{1, 61, 62, 125000, 3521614606207} {\n        fmt.Printf(\"id %d -&gt; %s\\n\", id, toBase62(id))\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>id 1 -&gt; 1\nid 61 -&gt; Z\nid 62 -&gt; 10\nid 125000 -&gt; ww8\nid 3521614606207 -&gt; ZZZZZZZ<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So seven characters cover IDs up to 3,521,614,606,207. A 302 redirect lets you count every click, while a 301 lets browsers cache it, which saves load but hides repeat clicks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q126. How do you generate unique IDs in a distributed system?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Auto-increment IDs from one database do not scale well and become a single point of failure. So systems use other methods.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Size<\/th><th>Sorted by time<\/th><th>Note<\/th><\/tr><\/thead><tbody><tr><td>UUID v4<\/td><td>128 bits<\/td><td>No<\/td><td>Random, no coordination, bad for B-tree index order<\/td><\/tr><tr><td>UUID v7<\/td><td>128 bits<\/td><td>Yes<\/td><td>Time-ordered, friendly to database indexes<\/td><\/tr><tr><td>Snowflake-style<\/td><td>64 bits<\/td><td>Yes<\/td><td>Time + machine ID + sequence<\/td><\/tr><tr><td>Database ranges<\/td><td>64 bits<\/td><td>Roughly<\/td><td>Each server takes a block of 1,000 IDs<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A Snowflake ID packs a timestamp, a machine ID and a sequence number into one 64-bit integer. Here is a simple version with a fixed time, so the output is the same every run.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nconst (\n    machineBits  = 10 \/\/ up to 1024 machines\n    sequenceBits = 12 \/\/ up to 4096 IDs per millisecond per machine\n)\n\n\/\/ makeID builds: [timestamp ms][machine id][sequence]\nfunc makeID(millis, machineID, sequence int64) int64 {\n    return millis&lt;&lt;(machineBits+sequenceBits) | machineID&lt;&lt;sequenceBits | sequence\n}\n\nfunc main() {\n    millis := int64(1_000_000) \/\/ milliseconds since our custom start date\n    id1 := makeID(millis, 5, 0)\n    id2 := makeID(millis, 5, 1)\n    id3 := makeID(millis+1, 2, 0)\n\n    fmt.Println(id1, id2, id3)\n    fmt.Println(\"sorted by time:\", id1 &lt; id2 &amp;&amp; id2 &lt; id3)\n\n    \/\/ Decode the parts back from id2.\n    fmt.Println(\"time:\", id2&gt;&gt;(machineBits+sequenceBits),\n        \"machine:\", (id2&gt;&gt;sequenceBits)&amp;(1&lt;&lt;machineBits-1),\n        \"sequence:\", id2&amp;(1&lt;&lt;sequenceBits-1))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>4194304020480 4194304020481 4194308202496\nsorted by time: true\ntime: 1000000 machine: 5 sequence: 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In a real generator, guard the sequence with a mutex, and wait for the next millisecond if the sequence runs out. Also watch for the clock moving backwards.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q127. How would you design a rate limiter service for many servers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Clients get a limit, such as 1,000 requests per hour per API key, and every API server must share the same count.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Where:<\/strong> at the API gateway or as middleware in each Go service.<\/li>\n\n\n<li><strong>Algorithm:<\/strong> token bucket or sliding window counter.<\/li>\n\n\n<li><strong>Storage:<\/strong> counters in Redis, updated with one atomic Lua script or <code>INCR<\/code> plus <code>EXPIRE<\/code>, so two servers cannot both take the last token.<\/li>\n\n\n<li><strong>Response:<\/strong> HTTP 429 Too Many Requests with a <code>Retry-After<\/code> header.<\/li>\n\n\n<li><strong>Failure plan:<\/strong> if Redis is down, decide to fail open (allow traffic) or fail closed (block). Most public APIs fail open with a local in-memory limit as backup.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q128. How would you design a chat application like WhatsApp?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Users send one-to-one and group messages, see online status and get messages after being offline.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Connections:<\/strong> clients keep a WebSocket open to a chat server. Go suits this well, because each connection needs only a goroutine or two.<\/li>\n\n\n<li><strong>Routing:<\/strong> a presence store in Redis maps <code>user_id -&gt; chat server<\/code>. To deliver a message, the sender&#8217;s server finds the receiver&#8217;s server and forwards it, often through a pub\/sub system.<\/li>\n\n\n<li><strong>Storage:<\/strong> messages go to a database built for heavy writes, such as Cassandra or ScyllaDB, partitioned by conversation ID and sorted by time.<\/li>\n\n\n<li><strong>Offline users:<\/strong> store the message, then send a push notification. When the user reconnects, they fetch unread messages.<\/li>\n\n\n<li><strong>Delivery status:<\/strong> sent, delivered and read are small events sent back to the sender.<\/li>\n\n\n<li><strong>Order:<\/strong> use a per-conversation sequence number, so messages show in the right order.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q129. How would you design a notification system?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The system sends notifications by email, SMS and mobile push, for many features such as order updates and OTPs.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>API:<\/strong> services call <code>POST \/notifications<\/code> with a user ID, a template and data.<\/li>\n\n\n<li><strong>Preferences:<\/strong> check what the user allowed, such as &#8220;no marketing SMS&#8221;, and quiet hours.<\/li>\n\n\n<li><strong>Queues:<\/strong> one queue per channel, so a slow email provider does not delay push messages.<\/li>\n\n\n<li><strong>Workers:<\/strong> Go workers read the queues and call providers, such as an email service, an SMS gateway, APNs and FCM.<\/li>\n\n\n<li><strong>Reliability:<\/strong> retries with backoff, a dead letter queue and idempotency keys, so a user never gets the same OTP twice.<\/li>\n\n\n<li><strong>Priority:<\/strong> OTPs and security alerts go in a high-priority queue ahead of marketing.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q130. How would you design a news feed like Instagram or Twitter?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Users follow others and see a timeline of recent posts from people they follow. The hard part is building feeds fast for millions of users.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Approach<\/th><th>How it works<\/th><th>Good for<\/th><th>Problem<\/th><\/tr><\/thead><tbody><tr><td>Fan-out on write (push)<\/td><td>On each new post, add it to every follower&#8217;s feed<\/td><td>Normal users, fast reads<\/td><td>Celebrities with millions of followers<\/td><\/tr><tr><td>Fan-out on read (pull)<\/td><td>Build the feed when the user opens the app<\/td><td>Celebrities<\/td><td>Slow reads<\/td><\/tr><tr><td>Hybrid<\/td><td>Push for normal users, pull for celebrities<\/td><td>Most real systems<\/td><td>More complex<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So use the hybrid approach. Keep each user&#8217;s feed as a list of post IDs in Redis, and fetch post details from a cache. Also use cursor pagination for scrolling.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q131. How would you design a file storage service like Google Drive or Dropbox?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Users upload, download, share and sync files across devices.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>File content:<\/strong> store files in object storage, split into chunks of a few megabytes. So only changed chunks are uploaded again, and failed uploads resume.<\/li>\n\n\n<li><strong>Deduplication:<\/strong> name each chunk by its content hash, so identical chunks are stored once.<\/li>\n\n\n<li><strong>Metadata:<\/strong> a SQL database holds folders, file names, versions, chunk lists and sharing rights.<\/li>\n\n\n<li><strong>Uploads:<\/strong> clients upload chunks straight to storage with pre-signed URLs.<\/li>\n\n\n<li><strong>Sync:<\/strong> when a file changes, a notification service tells the user&#8217;s other devices through a WebSocket or long polling.<\/li>\n\n\n<li><strong>Conflicts:<\/strong> if two devices edit offline, keep both versions and let the user choose.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q132. How would you design a payment system?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Correctness matters more than speed here, because money must never be lost or charged twice.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Idempotency keys<\/strong> on every payment request, so retries are safe.<\/li>\n\n\n<li><strong>A ledger<\/strong> with double-entry bookkeeping: every movement is a debit and a credit that add up to zero.<\/li>\n\n\n<li><strong>Strong consistency<\/strong> with a SQL database and transactions for balances.<\/li>\n\n\n<li><strong>State machine<\/strong> for each payment: created, pending, succeeded, failed, refunded.<\/li>\n\n\n<li><strong>External providers<\/strong> (card networks, UPI, banks) are called through a separate service with timeouts, retries and webhooks for final status.<\/li>\n\n\n<li><strong>Reconciliation:<\/strong> a daily job compares your records with the provider&#8217;s reports and flags any mismatch.<\/li>\n\n\n<li><strong>Audit:<\/strong> never delete or update ledger rows. Add correcting entries instead.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Also, never store raw card numbers yourself. Use a payment provider&#8217;s tokenization, so your system stays out of most PCI DSS scope.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q133. How would you design a ride-hailing service like Uber or Ola?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Riders request a ride, and the system matches them with a nearby driver.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Location updates:<\/strong> drivers send their GPS position every few seconds. That is a huge write load, so keep current positions in memory or Redis, not in the main database.<\/li>\n\n\n<li><strong>Finding nearby drivers:<\/strong> split the map into cells with geohash, S2 or H3, then search the rider&#8217;s cell and its neighbours. Redis also has built-in geo commands.<\/li>\n\n\n<li><strong>Matching:<\/strong> a matching service offers the ride to the best driver and waits a few seconds for acceptance, then tries the next one.<\/li>\n\n\n<li><strong>Trip service:<\/strong> stores trips with a state machine, from requested to completed.<\/li>\n\n\n<li><strong>Pricing:<\/strong> surge pricing based on demand and supply in each area.<\/li>\n\n\n<li><strong>Real-time updates:<\/strong> WebSockets or push notifications to show the car moving.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q134. How would you design a real-time leaderboard?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A gaming app shows the top 100 players and each player&#8217;s own rank, updated live.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Redis sorted sets fit this problem well. <code>ZINCRBY leaderboard 50 player:7<\/code> adds points, <code>ZREVRANGE leaderboard 0 99 WITHSCORES<\/code> returns the top 100, and <code>ZREVRANK<\/code> gives one player&#8217;s rank. All of these are fast even with millions of players.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For daily or weekly boards, use one key per period, such as <code>leaderboard:2026-w43<\/code>, with an expiry. Also save scores in a database, so you can rebuild Redis if it fails.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q135. How would you design search autocomplete?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a user types &#8220;go la&#8221;, the system suggests &#8220;go language&#8221;, &#8220;golang jobs&#8221; and so on within about 100 milliseconds.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Data structure:<\/strong> a trie (prefix tree), where each node stores the top suggestions for that prefix. So a lookup is just walking down a few letters.<\/li>\n\n\n<li><strong>Building:<\/strong> a background job counts popular search terms from logs and rebuilds the trie, for example every hour.<\/li>\n\n\n<li><strong>Serving:<\/strong> keep the trie in memory in Go services, or store <code>prefix -&gt; top 10<\/code> in Redis.<\/li>\n\n\n<li><strong>Client side:<\/strong> wait about 100 ms after the last key press (debounce) and cache recent answers in the browser.<\/li>\n\n\n<li><strong>Safety:<\/strong> filter offensive terms before they reach the list.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q136. How would you design a distributed job scheduler?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The system runs jobs at a set time or on a schedule, such as &#8220;send invoices on the 1st of every month&#8221;, across many workers.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Job store:<\/strong> a database table with <code>id, run_at, status, attempts, payload<\/code>.<\/li>\n\n\n<li><strong>Picking jobs:<\/strong> workers run <code>SELECT ... WHERE run_at &lt;= now() AND status = 'pending' FOR UPDATE SKIP LOCKED LIMIT 10<\/code>, so two workers never take the same job.<\/li>\n\n\n<li><strong>Execution:<\/strong> workers mark jobs as running, do the work, then mark them done or failed.<\/li>\n\n\n<li><strong>Retries:<\/strong> failed jobs get a new <code>run_at<\/code> with backoff, up to a maximum.<\/li>\n\n\n<li><strong>Stuck jobs:<\/strong> a job in &#8220;running&#8221; with no heartbeat for too long goes back to pending.<\/li>\n\n\n<li><strong>Idempotent jobs:<\/strong> because a job may run twice after a crash.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q137. How would you design a web crawler?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The crawler downloads pages, finds links and keeps going, for example to build a search index.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>URL frontier:<\/strong> a queue of URLs to visit, with priorities.<\/li>\n\n\n<li><strong>Politeness:<\/strong> respect <code>robots.txt<\/code> and limit requests per domain, using one queue per host.<\/li>\n\n\n<li><strong>Fetchers:<\/strong> many Go workers download pages concurrently with timeouts.<\/li>\n\n\n<li><strong>Deduplication:<\/strong> a Bloom filter or a set of URL hashes stops visiting the same page twice, and content hashes catch duplicate pages.<\/li>\n\n\n<li><strong>Parsing:<\/strong> extract links and text, then add new links to the frontier.<\/li>\n\n\n<li><strong>Storage:<\/strong> raw pages go to object storage, and extracted data goes to the indexer.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q138. How would you design a ticket booking or flash sale system?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thousands of users try to buy a limited number of items at the same moment, such as 500 concert seats.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Prevent overselling:<\/strong> use an atomic update such as <code>UPDATE seats SET status='held' WHERE id=$1 AND status='free'<\/code>, and check that exactly one row changed. Or use an atomic counter in Redis.<\/li>\n\n\n<li><strong>Temporary holds:<\/strong> a seat is held for a few minutes while the user pays, then released automatically if payment fails.<\/li>\n\n\n<li><strong>Virtual waiting room:<\/strong> put users in a queue and let them in at a rate the backend can handle.<\/li>\n\n\n<li><strong>Cache static data:<\/strong> event details and seat maps come from a CDN or cache, not the database.<\/li>\n\n\n<li><strong>Rate limit and bot checks:<\/strong> stop scripts from grabbing all seats.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to Answer System Design Interview Questions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Knowing the parts is only half the work. These system design interview questions are about the interview itself: how to run the 45 minutes, estimate numbers and talk about trade-offs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q139. What steps should you follow in a system design interview?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the same simple plan every time, so you never freeze.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Clarify requirements (about 5 minutes):<\/strong> ask what the system must do and for how many users.<\/li>\n\n\n<li><strong>Estimate the scale (about 5 minutes):<\/strong> requests per second, storage and bandwidth.<\/li>\n\n\n<li><strong>Define the API and data model (about 5 minutes):<\/strong> main endpoints and tables.<\/li>\n\n\n<li><strong>Draw the high-level design (about 10 minutes):<\/strong> clients, load balancer, services, cache, database, queue.<\/li>\n\n\n<li><strong>Go deeper on key parts (about 15 minutes):<\/strong> the hardest piece, such as feed generation or ID creation.<\/li>\n\n\n<li><strong>Discuss bottlenecks and trade-offs (about 5 minutes):<\/strong> failures, scaling, monitoring and what you would improve.<\/li>\n\n<\/ol>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-3-1024x640.png\" alt=\"System design interview questions answer steps from requirements to trade-offs\" class=\"wp-image-956\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-3-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-3-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-3-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-3-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-diagram-3-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Six steps to answer any design question: requirements, estimates, API and data, high-level design, detail on key parts, and trade-offs.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Talk while you draw, and check with the interviewer often. They want to see your thinking, not a perfect final picture.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q140. What is the difference between functional and non-functional requirements?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Functional requirements say what the system does. For example, &#8220;users can post a photo&#8221; and &#8220;users can follow others&#8221;. Non-functional requirements say how well it does it, such as speed, availability, consistency, security and cost.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Type<\/th><th>Example for a URL shortener<\/th><\/tr><\/thead><tbody><tr><td>Functional<\/td><td>Create a short link, redirect to the long URL, optional expiry<\/td><\/tr><tr><td>Non-functional<\/td><td>Redirect under 50 ms, 99.99% available, codes not guessable<\/td><\/tr><tr><td>Scale<\/td><td>100 million new links per month, 100 reads per write<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So write both lists on the board first. Many later decisions, such as SQL or NoSQL, depend on the non-functional list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q141. How do you do back-of-the-envelope estimation?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You make quick, rounded calculations to size the system. Exact numbers do not matter, but the order of size does, such as 100 or 100,000 requests per second. Here are handy shortcuts.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>One day has about 86,400 seconds, so round it to 100,000.<\/li>\n\n\n<li>1 million requests per day is about 12 per second on average.<\/li>\n\n\n<li>Peak traffic is often 2 to 10 times the average.<\/li>\n\n\n<li>1 KB times 1 million is 1 GB, and 1 KB times 1 billion is 1 TB.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a small Go program that does the math for a URL shortener.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    newLinksPerMonth := 100_000_000.0\n    readsPerWrite := 100.0\n    bytesPerLink := 500.0 \/\/ code + long URL + metadata\n    secondsPerMonth := 30 * 24 * 3600.0\n    years := 5.0\n\n    writesPerSec := newLinksPerMonth \/ secondsPerMonth\n    readsPerSec := writesPerSec * readsPerWrite\n    storageTB := newLinksPerMonth * 12 * years * bytesPerLink \/ 1e12\n\n    fmt.Printf(\"writes per second: %.0f\\n\", writesPerSec)\n    fmt.Printf(\"reads per second:  %.0f\\n\", readsPerSec)\n    fmt.Printf(\"peak reads (x5):   %.0f\\n\", readsPerSec*5)\n    fmt.Printf(\"storage for %v years: %.1f TB\\n\", years, storageTB)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>writes per second: 39\nreads per second:  3858\npeak reads (x5):   19290\nstorage for 5 years: 3.0 TB<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So about 4,000 reads per second is easy for a cached Go service, and 3 TB fits in one sharded database. This tells you the design does not need anything exotic.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q142. What latency numbers should every engineer know?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These rough numbers help you guess where time goes. Exact values change with hardware, but the size differences stay.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Operation<\/th><th>Rough time<\/th><\/tr><\/thead><tbody><tr><td>Read from main memory<\/td><td>About 100 nanoseconds<\/td><\/tr><tr><td>Read 1 MB from memory<\/td><td>A few microseconds to about 0.25 ms<\/td><\/tr><tr><td>Round trip inside one data centre<\/td><td>About 0.5 ms<\/td><\/tr><tr><td>Random read from an SSD<\/td><td>About 0.1 ms<\/td><\/tr><tr><td>Redis GET over the network<\/td><td>Under 1 ms<\/td><\/tr><tr><td>Simple indexed SQL query<\/td><td>1 to 5 ms<\/td><\/tr><tr><td>Round trip between continents<\/td><td>About 150 ms<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So memory is much faster than disk, and disk is much faster than a network trip across the world. This is why caching and placing data near users matter so much.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q143. How do you talk about trade-offs?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Every design choice has a cost, and interviewers want you to name it. Use a simple pattern: &#8220;I chose X because of Y, and the cost is Z&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example: &#8220;I chose eventual consistency for the like counter because it keeps writes fast at high volume. The cost is that counts may lag for a second, which is fine here.&#8221; Common trade-off pairs are consistency vs availability, latency vs consistency, cost vs performance, and simplicity vs flexibility.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q144. What do interviewers expect from junior, mid-level and senior developers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The bar changes with the role.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Level<\/th><th>What they look for<\/th><\/tr><\/thead><tbody><tr><td>Junior or fresher<\/td><td>Basic parts, clear API and tables, a working simple design<\/td><\/tr><tr><td>Mid-level<\/td><td>Scaling with caches, queues and replicas, failure handling<\/td><\/tr><tr><td>Senior<\/td><td>Trade-offs, bottlenecks, data consistency, cost, monitoring, leading the discussion<\/td><\/tr><tr><td>Staff and above<\/td><td>Multi-region, team boundaries, migration plans, long-term evolution<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So freshers should not panic about advanced topics. Show a clean, working design and explain each box simply.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q145. What should you do if you do not know the answer to a design question?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Be honest and reason it out aloud. Say what you do know, make a clear assumption and continue. For example: &#8220;I have not used Cassandra in production, but I know it suits heavy writes with a partition key, so I would check that for this use case.&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Interviewers value clear thinking more than knowing every tool. Guessing with confidence and being wrong hurts more than a calm &#8220;here is how I would find out&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q146. What follow-up questions should you expect after your design?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Interviewers often push on the weak spots. So prepare short answers for these.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>What happens if this database or region goes down?<\/li>\n\n\n<li>How would this work with 10 times more traffic?<\/li>\n\n\n<li>Where is the bottleneck now?<\/li>\n\n\n<li>How do you keep the cache and database in sync?<\/li>\n\n\n<li>How do you monitor this and know it is healthy?<\/li>\n\n\n<li>What would you build first with a small team and two weeks?<\/li>\n\n\n<li>How much would this cost to run?<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Practise these with our <a href=\"https:\/\/smitabharat.com\/blog\/go-system-design-scenarios\/\">Go system design scenarios<\/a>, which walk through real cases step by step.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes in System Design Interviews<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Jumping straight to the diagram:<\/strong> always ask about requirements and scale first, because they decide everything else.<\/li>\n\n\n<li><strong>Using every tool you know:<\/strong> Kafka, Kubernetes and five databases for a small app look like guessing, not design.<\/li>\n\n\n<li><strong>Ignoring failures:<\/strong> say what happens when each box dies, and add timeouts, retries and backups.<\/li>\n\n\n<li><strong>No numbers:<\/strong> a quick estimate shows whether you need one server or a thousand.<\/li>\n\n\n<li><strong>Staying silent:<\/strong> think aloud, so the interviewer can follow and guide you.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Answering System Design Interview Questions<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Start simple, then scale:<\/strong> draw a working basic design first, then improve the bottlenecks.<\/li>\n\n\n<li><strong>Name the trade-off:<\/strong> for each choice, say what you gain and what it costs.<\/li>\n\n\n<li><strong>Use your Go knowledge:<\/strong> mention <code>context<\/code> timeouts, worker pools, graceful shutdown and pprof where they fit.<\/li>\n\n\n<li><strong>Use real examples:<\/strong> a project you built, with real numbers, is more convincing than theory.<\/li>\n\n\n<li><strong>Practise on paper or a whiteboard:<\/strong> time yourself to 45 minutes per problem.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Pick one classic problem from this list, such as the URL shortener or the notification system. Set a 45-minute timer and answer it out loud with the six steps from the answer method above. Hint: write the requirements and estimates in one corner of the page first, and refer back to them at every decision.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/go.dev\/doc\/effective_go\">Effective Go<\/a><\/li>\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/context\">Go context package<\/a><\/li>\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/net\/http\">Go net\/http package<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/doc\/diagnostics\">Go diagnostics guide<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>These system design interview questions run from basics to full design problems, all in simple English.<\/li>\n\n\n<li>Learn the building blocks first: load balancers, caches, databases, queues and monitoring.<\/li>\n\n\n<li>Know the key trade-offs, such as consistency vs availability and SQL vs NoSQL.<\/li>\n\n\n<li>Use Go features in your answers, such as goroutines, <code>context<\/code>, worker pools and graceful shutdown.<\/li>\n\n\n<li>Follow the six-step method, and practise the classic problems out loud.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For more Go-focused architecture practice, read our <a href=\"https:\/\/smitabharat.com\/blog\/go-architecture-interview-questions-part-26\/\">Go architecture interview questions<\/a> and <a href=\"https:\/\/smitabharat.com\/blog\/go-microservices-interview-questions-part-24\/\">Go microservices interview questions<\/a>. Then test yourself with the shorter <a href=\"https:\/\/smitabharat.com\/blog\/go-interview-questions\/\">Go interview questions<\/a> list.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>System design interview questions are now part of almost every Go developer interview, from fresher roles to senior backend jobs. This post gives you&hellip;<\/p>\n","protected":false},"author":1,"featured_media":953,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[10],"tags":[95,77,126,136],"swapz_series":[],"class_list":["post-957","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-interview","tag-go-interview-questions","tag-intermediate","tag-interview-questions","tag-system-design"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>System Design Interview Questions for Go Developers<\/title>\n<meta name=\"description\" content=\"System design interview questions for Go developers, basic to advanced: scaling, caching, databases, queues, reliability and classic design problems.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"System Design Interview Questions for Go Developers\" \/>\n<meta property=\"og:description\" content=\"System design interview questions for Go developers, basic to advanced: scaling, caching, databases, queues, reliability and classic design problems.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-13T05:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-28T19:59:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"65 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/system-design-interview-questions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/system-design-interview-questions\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"System Design Interview Questions: 140+ Q&amp;A for Go Developers\",\"datePublished\":\"2026-10-13T05:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/system-design-interview-questions\\\/\"},\"wordCount\":14536,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/system-design-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/system-design-interview-questions-featured.png\",\"keywords\":[\"Go Interview Questions\",\"Intermediate\",\"Interview Questions\",\"System Design\"],\"articleSection\":[\"Interview\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/system-design-interview-questions\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/system-design-interview-questions\\\/\",\"name\":\"System Design Interview Questions for Go Developers\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/system-design-interview-questions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/system-design-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/system-design-interview-questions-featured.png\",\"datePublished\":\"2026-10-13T05:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:22+00:00\",\"description\":\"System design interview questions for Go developers, basic to advanced: scaling, caching, databases, queues, reliability and classic design problems.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/system-design-interview-questions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/system-design-interview-questions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/system-design-interview-questions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/system-design-interview-questions-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/system-design-interview-questions-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"System Design Interview Questions featured image: basic to advanced design answers for Go developers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/system-design-interview-questions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"System Design Interview Questions: 140+ Q&amp;A for Go Developers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"System Design Interview Questions for Go Developers","description":"System design interview questions for Go developers, basic to advanced: scaling, caching, databases, queues, reliability and classic design problems.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/","og_locale":"en_US","og_type":"article","og_title":"System Design Interview Questions for Go Developers","og_description":"System design interview questions for Go developers, basic to advanced: scaling, caching, databases, queues, reliability and classic design problems.","og_url":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-10-13T05:30:00+00:00","article_modified_time":"2026-11-28T19:59:22+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"65 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"System Design Interview Questions: 140+ Q&amp;A for Go Developers","datePublished":"2026-10-13T05:30:00+00:00","dateModified":"2026-11-28T19:59:22+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/"},"wordCount":14536,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-featured.png","keywords":["Go Interview Questions","Intermediate","Interview Questions","System Design"],"articleSection":["Interview"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/","url":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/","name":"System Design Interview Questions for Go Developers","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-featured.png","datePublished":"2026-10-13T05:30:00+00:00","dateModified":"2026-11-28T19:59:22+00:00","description":"System design interview questions for Go developers, basic to advanced: scaling, caching, databases, queues, reliability and classic design problems.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/system-design-interview-questions-featured.png","width":2400,"height":1260,"caption":"System Design Interview Questions featured image: basic to advanced design answers for Go developers"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/system-design-interview-questions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"System Design Interview Questions: 140+ Q&amp;A for Go Developers"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=957"}],"version-history":[{"count":2,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/957\/revisions"}],"predecessor-version":[{"id":961,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/957\/revisions\/961"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/953"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=957"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}