Caching Flashcards

1
Q

What are L1, L2, and L3 caches in computer hardware, and how do they differ?

A

L1 cache is the smallest and fastest, integrated into the CPU and stores frequently accessed data. L2 cache is larger but slower than L1, located on the CPU die or a separate chip. L3 cache is larger and slower than L2, often shared between CPU cores.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the role of the Translation Lookaside Buffer (TLB) in hardware caching?

A

The TLB stores recently used virtual-to-physical address translations, enabling the CPU to quickly translate memory addresses, reducing data access time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the function of the page cache and file system caches at the operating system level?

A

Page cache, managed by the OS and residing in main memory, stores recently used disk blocks. File system caches like inode cache speed up file operations by reducing disk accesses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do web browsers and Content Delivery Networks (CDNs) utilize caching at the application front end?

A

Web browsers cache HTTP responses for faster data retrieval. CDNs cache static content like images and videos on edge servers to speed up content delivery.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the role of caching in load balancers and messaging infrastructure like Kafka?

A

Load balancers can cache responses to reduce back-end server load. Kafka caches messages on disk, allowing consumers to retrieve them at their own pace based on retention policy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do distributed caches like Redis and full-text search engines like Elastic Search use caching?

A

Redis stores key-value pairs in memory for high performance. Elastic Search indexes data for efficient document and log search.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What caching mechanisms are found within databases?

A

Databases use write-ahead logs (WAL), buffer pools to cache query results, materialized views for precomputed queries, transaction logs for recording updates, and replication logs for tracking database cluster state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why is caching data essential in system architecture?

A

Caching is crucial for optimizing system performance and reducing response time across various layers and applications in a computing system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the significance of the L1 cache being integrated into the CPU?

A

The integration of L1 cache directly into the CPU minimizes latency, allowing for the fastest possible access to frequently used data and instructions, which enhances CPU performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does the Translation Lookaside Buffer (TLB) improve CPU efficiency?

A

The TLB improves CPU efficiency by storing recent virtual-to-physical address translations, enabling quick memory address translation and reducing the time required for memory access.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why is the page cache important in an operating system?

A

The page cache is important as it stores disk blocks in main memory, allowing the operating system to quickly serve data from memory rather than the slower process of reading from the disk.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the advantage of using Content Delivery Networks (CDNs) for caching?

A

CDNs enhance content delivery by caching static web assets like images and videos closer to the user, reducing latency and bandwidth usage, and improving load times for web pages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do load balancers utilize caching to improve system performance?

A

Load balancers use caching to store responses from back-end servers, allowing them to serve repeated requests more quickly and efficiently, thus reducing the load on back-end servers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the purpose of caching messages in Kafka’s messaging infrastructure?

A

In Kafka, caching messages on disk allows for efficient message handling and retrieval, enabling consumers to process messages at their own pace and ensuring message availability over extended periods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How does caching in Redis differ from traditional database operations?

A

Redis uses in-memory caching for key-value pairs, offering significantly faster read/write performance compared to traditional databases that rely more on disk-based storage.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In what ways do databases implement caching to enhance performance?

A

Databases implement caching through mechanisms like write-ahead logs for ensuring data integrity, buffer pools for storing frequently accessed data in memory, and materialized views for quick retrieval of complex query results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Why is the L2 cache slower than the L1 cache?

A

The L2 cache is larger and typically located further from the CPU core compared to the L1 cache. This increased distance and size result in slightly higher latency, making L2 cache slower than L1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How does an inode cache enhance file system performance?

A

The inode cache stores metadata about file system objects (like files and directories), enabling quicker access to this information and reducing the need for frequent disk reads, thus speeding up file system operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What role does caching play in HTTP response handling by web browsers?

A

When a web browser caches HTTP responses, it stores copies of frequently accessed web resources. This allows the browser to load these resources from the cache rather than fetching them again from the web server, speeding up web page loading.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do databases use Write-Ahead Logs (WAL) for caching?

A

In databases, WALs are used to record changes before they are written to the main database. This ensures data integrity and allows for recovery in case of a system crash. The WAL also serves as a form of cache by allowing quick writes to a log, reducing immediate write load on the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the significance of shared L3 cache among CPU cores?

A

Shared L3 cache among CPU cores allows multiple cores to access a larger common cache. This facilitates efficient data sharing and reduces the need for data duplication across cores, enhancing overall CPU cache utilization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How does caching in a full-text search engine like Elastic Search improve performance?

A

Elastic Search uses caching to store frequently accessed data and query results. This accelerates search operations by reducing the need to reprocess or reaccess data from the primary storage, leading to faster search response times.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the function of a buffer pool in a database system?

A

A buffer pool in a database system caches pages of data in memory. This allows quicker access to these pages, reducing disk I/O and improving database query performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How do Content Delivery Networks (CDNs) optimize caching based on geographic location?

A

CDNs cache content in multiple geographically distributed servers (edge servers). This ensures that content is delivered from the nearest server to the user, reducing latency and improving loading times for users in different locations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is CPU cache and what type of memory does it use?

A

CPU cache is the CPU’s internal memory designed to store copies of data and instructions from RAM that the CPU is likely to use frequently. It uses SRAM (Static RAM), which is faster than DRAM (Dynamic RAM) used in RAM modules because it doesn’t need to be constantly refreshed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

How does SRAM differ from DRAM in terms of operation and cost?

A

SRAM, used in CPU cache, doesn’t require constant refreshing, making it faster than DRAM. However, SRAM is more expensive to produce compared to DRAM.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Why is CPU cache important for computer performance?

A

CPU cache is crucial because it allows the CPU to access frequently used data quickly. If the needed data is in the cache, the CPU doesn’t have to wait for slower RAM, thus avoiding bottlenecks and enhancing overall computer performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What would happen if a computer did not have CPU cache?

A

Without CPU cache, a computer would be slower because the CPU would frequently have to wait for data from the slower RAM, creating a performance bottleneck.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

How are the different levels of CPU cache (L1, L2, and L3) structured and functionally different?

A

L1 cache, the fastest and smallest, is located on the processor and runs at the processor’s speed. L2 cache is larger but slower than L1 and is used when data isn’t found in L1. L3 cache, larger than L2 but slower, is used when data isn’t in L2. L3 is shared across CPU cores, while L1 and L2 are dedicated to individual cores.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

How has the location of the L2 cache evolved in modern CPUs compared to earlier computers?

A

In earlier computers, the L2 cache was located on a separate chip on the motherboard. In modern CPUs, it is integrated into the processor, which improves its speed and efficiency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Why is the L3 cache referred to as ‘shared cache’?

A

The L3 cache is called ‘shared cache’ because it is shared between all the cores on a CPU. This contrasts with L1 and L2 caches, which are dedicated to individual CPU cores.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

How do the sizes and speeds of L1, L2, and L3 caches compare?

A

The L1 cache is the smallest and fastest, L2 is larger but slower than L1, and L3 is the largest but the slowest among the three. Each level of cache is designed to balance speed and size to optimize CPU performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is the role of CPU cache in reducing processing time?

A

The CPU cache reduces processing time by storing frequently accessed data and instructions close to the CPU. This proximity allows for quicker access compared to fetching data from slower main memory (RAM), thereby speeding up processing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

How does CPU cache contribute to the efficiency of multi-core processors?

A

In multi-core processors, the shared L3 cache allows cores to efficiently access and share common data, reducing the need for each core to fetch the same data from RAM. This shared access improves data coherence and overall efficiency in multi-core systems.

35
Q

Why is SRAM more expensive than DRAM despite its smaller size?

A

SRAM is more expensive due to its complex internal structure which requires more transistors per bit of storage compared to DRAM. This complexity provides faster access but increases production costs.

36
Q

How does the CPU determine what data to store in its cache?

A

The CPU uses algorithms to predict which data and instructions it will need next, based on recent accesses and patterns of usage. This predictive approach helps in storing relevant data in the cache for faster access.

37
Q

What happens when the CPU cache does not contain the required data?

A

This situation is known as a ‘cache miss.’ When the required data is not found in the cache, the CPU must fetch the data from the slower main memory (RAM), resulting in increased access time and potential processing delays.

38
Q

Can the efficiency of CPU cache affect overall computer performance?

A

Yes, the efficiency of the CPU cache significantly affects overall computer performance. A well-optimized cache reduces the frequency of accessing slower RAM, thereby minimizing bottlenecks and enhancing system speed.

39
Q

What impact does the size of the CPU cache have on computing tasks?

A

The size of the CPU cache impacts how much data can be quickly accessed by the CPU. Larger caches can store more data, potentially reducing the need to access slower main memory and improving performance, especially in data-intensive tasks.

40
Q

Is CPU cache visible to the operating system or software applications?

A

No, the CPU cache is not directly visible or accessible to the operating system or software applications. It is managed internally by the CPU’s hardware and caching algorithms.

41
Q

What is a CDN (Content Delivery Network)?

A

A CDN is a network of servers strategically distributed globally, designed to deliver web content quickly to users by hosting content closer to where the users are. It speeds up the delivery of static and dynamic content over the internet.

42
Q

How does a CDN improve web service performance for users?

A

A CDN improves web service performance by reducing latency. It hosts content on edge servers located close to users, ensuring faster content delivery and improved user experience.

43
Q

What are the key components of a CDN?

A

Key components of a CDN include Points of Presence (PoPs), which are server locations around the world, and edge servers within these PoPs that cache and deliver content to users.

44
Q

What technologies do CDNs use to direct user requests efficiently?

A

CDNs use technologies like DNS-based routing, where each PoP has its own IP address, and Anycast, where all PoPs share the same IP address, to direct user requests to the closest PoP efficiently.

45
Q

What is the role of edge servers in a CDN?

A

Edge servers in a CDN act as reverse proxies with large content caches. They store static content, delivering it quickly to users, and reduce the load on origin servers by requesting content only when it’s not in the cache.

46
Q

How do modern CDNs optimize static content?

A

Modern CDNs can transform static content into more optimized formats, such as minifying JavaScript bundles or converting images into modern formats like WebP or AVIF, improving load times and efficiency.

47
Q

Why is TLS termination at the edge server important in a CDN?

A

Terminating TLS connections at the edge server reduces latency in establishing encrypted TCP connections, as TLS handshakes are resource-intensive and can involve several network round trips.

48
Q

What security benefits do modern CDNs offer?

A

Modern CDNs provide enhanced security, including effective DDoS protection, by utilizing their vast network capacity to absorb and diffuse attack traffic across numerous servers, especially in Anycast-based networks.

49
Q

How does a CDN improve availability and reliability?

A

A CDN’s highly distributed nature, with content replicated in multiple PoPs, enhances system availability and reliability. It can withstand more hardware failures than origin servers, ensuring content is always accessible.

50
Q

Why should developers use a CDN for serving HTTP traffic?

A

Developers should use a CDN for serving HTTP traffic because it significantly enhances performance, security, and availability of web services, leading to better user engagement and retention.

51
Q

What is the significance of load balancing in a CDN?

A

Load balancing in a CDN distributes incoming traffic among various servers within the network, preventing any single server from becoming overwhelmed and ensuring consistent, efficient content delivery.

52
Q

Why are CDNs particularly important for mobile content delivery?

A

CDNs are vital for mobile content delivery because they optimize content for faster loading on mobile devices, which is crucial given the typically slower mobile network speeds and higher sensitivity to latency.

53
Q

How do CDNs contribute to SEO (Search Engine Optimization)?

A

CDNs can improve website speed and user experience, both of which are factors in SEO rankings. Faster websites are more likely to be ranked higher in search engine results, increasing visibility.

54
Q

Can CDNs help in mitigating website downtimes?

A

Yes, CDNs can help mitigate downtimes by distributing content across multiple servers. If one server goes down, others can step in to serve the content, ensuring continuous availability.

55
Q

What is vertical scaling and when is it used?

A

Vertical scaling involves adding more resources like RAM or upgrading the CPU to an existing server. It’s an easy method to increase capacity but has limitations in scalability and resilience.

56
Q

How does horizontal scaling enhance system performance?

A

Horizontal scaling involves adding more servers to handle the workload. Each server can handle a subset of requests, enhancing performance, scalability, fault tolerance, and eliminating single points of failure.

57
Q

What is the role of a load balancer in a horizontally scaled system?

A

A load balancer, acting as a reverse proxy, distributes incoming requests evenly across multiple servers. It prevents any single server from being overloaded, ensuring efficient resource utilization.

58
Q

Why are Content Delivery Networks (CDNs) crucial for serving static files?

A

CDNs, with servers worldwide, are essential for serving static files (like images, videos, HTML, CSS, and JavaScript) as they reduce latency by serving content from the nearest server to the user.

59
Q

How does caching contribute to system efficiency?

A

Caching creates copies of data for faster retrieval, reducing the need for repeated data fetching. It enhances performance at various levels, from browser disk caching to memory and CPU cache.

60
Q

What is TCP/IP and its significance in data communication?

A

TCP/IP (Transmission Control Protocol/Internet Protocol) is a set of networking protocols governing how data is transmitted over the internet. TCP ensures reliable data transmission, forming the basis for many internet protocols.

61
Q

How does the Domain Name System (DNS) facilitate internet browsing?

A

DNS translates human-readable domain names (like neetcode.io) into IP addresses, allowing browsers to locate and access websites. It’s essential for navigating the internet efficiently.

62
Q

What is the purpose of the HTTP protocol in web communication?

A

HTTP (Hypertext Transfer Protocol) is an application-level protocol facilitating the transfer of web content. It simplifies data communication between clients and servers, structuring requests and responses.

63
Q

How do REST and GraphQL differ in API design?

A

REST is a standardized approach making HTTP APIs stateless and uniform. GraphQL allows fetching multiple resources in a single request, reducing over-fetching and under-fetching issues common in REST APIs.

64
Q

What is the difference between SQL and NoSQL databases in data management?

A

SQL databases are relational, structured, and ACID-compliant, ideal for complex queries and relationships. NoSQL databases are non-relational, offering more flexibility and scalability, suitable for varied data types and large-scale applications.

65
Q

What are the advantages and challenges of sharding in databases?

A

Sharding involves distributing data across multiple servers to enhance performance and scalability. The advantage is improved load distribution and scalability. However, it can be complex to implement and manage, especially in maintaining data consistency and balancing the load across shards.

66
Q

How do leader-follower and leader-leader replications differ in databases?

A

In leader-follower replication, all writes are directed to the leader, which then replicates the data to followers. In leader-leader replication, each replica can handle reads and writes, offering higher availability but increasing the risk of data inconsistency.

67
Q

What is the CAP theorem and its significance in distributed systems?

A

The CAP theorem states that a distributed database system can only simultaneously provide two of the three: Consistency, Availability, and Partition tolerance. It’s crucial for understanding the trade-offs in distributed system design.

68
Q

What role do message queues play in system architecture?

A

Message queues decouple different parts of an application, allowing for asynchronous data processing and communication. They help manage load, ensure data integrity during high traffic, and improve system resilience.

69
Q

Why is horizontal scaling favored over vertical scaling in large-scale systems?

A

Horizontal scaling, or adding more servers, is favored for its almost infinite scalability and enhanced fault tolerance. Unlike vertical scaling, it doesn’t have the physical limitations of a single machine and allows for redundancy.

70
Q

What is the role of protocol buffers in system performance?

A

Protocol buffers are a method of serializing structured data. They are more efficient than JSON, as they serialize data into a binary format, which is less storage-intensive and faster to transmit over networks.

71
Q

How do WebSockets enhance real-time communication in web applications?

A

WebSockets allow for bi-directional, real-time communication between clients and servers. Unlike traditional HTTP, they enable a continuous connection, ideal for applications requiring instant data updates like chat apps.

72
Q

What is the significance of the HTTP/2 protocol?

A

HTTP/2 is an evolution of HTTP that enables more efficient use of network resources and reduced latency. It allows multiplexing, where multiple requests and responses can be in flight at the same time over a single TCP connection.

73
Q

How do GRPC and REST differ in inter-service communication?

A

GRPC, a high-performance RPC framework, uses protocol buffers and is ideal for efficient server-to-server communication. REST, based on standard HTTP, is more flexible and easier to use for a wide range of web services.

74
Q

What is the purpose of using DNS A records?

A

DNS A records (Address Records) map a domain name to its corresponding IP address. They are essential for directing user traffic to the correct server when a domain name is entered into a browser.

75
Q

What is the purpose of a reverse proxy in a network architecture?

A

A reverse proxy serves as an intermediary for requests from clients seeking resources from servers. It provides functions like load balancing, authentication, SSL termination, and caching to enhance security, performance, and scalability.

76
Q

How does the concept of ‘fault tolerance’ impact system design?

A

Fault tolerance refers to a system’s ability to continue operating without interruption when one or more of its components fail. Designing for fault tolerance involves redundancy, failover mechanisms, and robust error handling to ensure system reliability and availability.

77
Q

What are the benefits of using stateless servers in a scalable architecture?

A

Stateless servers do not retain user session information, which simplifies scaling and load balancing. They enhance system resilience and reliability, as any server can handle any request, making it easier to add or remove servers without impacting user experience.

78
Q

What is a B-tree, and why is it important in databases?

A

A B-tree is a balanced tree data structure commonly used in databases and file systems for storing and managing large amounts of sorted data. It allows efficient insertion, deletion, and retrieval operations, making it crucial for database indexing and performance.

79
Q

How do ACID properties ensure reliable database transactions?

A

ACID properties (Atomicity, Consistency, Isolation, Durability) ensure reliable transactions in a database. Atomicity guarantees all-or-nothing execution, Consistency ensures data validity, Isolation prevents transaction interference, and Durability means completed transactions are permanently recorded.

80
Q

Why is load balancing essential in a distributed system?

A

Load balancing distributes workloads across multiple computing resources, preventing any single resource from becoming overwhelmed. It ensures optimal resource utilization, maximizes throughput, minimizes response time, and prevents overload.

81
Q

What is a microservices architecture, and how does it benefit large-scale applications?

A

Microservices architecture involves developing an application as a collection of small, independent services. It benefits large-scale applications by enabling better scalability, faster development cycles, and easier maintenance and deployment.

82
Q

How do content transformation and optimization at the edge servers of a CDN enhance web performance?

A

Edge servers in a CDN can transform and optimize content (like compressing images, minifying JS/CSS) closer to the user. This reduces payload sizes and loading times, improving overall web performance and user experience.

83
Q

What is the difference between synchronous and asynchronous communication in distributed systems?

A

Synchronous communication requires the sender to wait for a response, potentially causing delays. Asynchronous communication allows the sender to continue processing other tasks, improving system responsiveness and efficiency.

84
Q

Why are distributed systems often preferred for modern, high-traffic applications?

A

Distributed systems are preferred due to their ability to handle high volumes of traffic and data. They offer scalability, reliability, and availability by distributing load and services across multiple interconnected nodes.