# Have you noticed how slow the product details page is lately?

## Conversation

### Dialog

**Roger**: Hey Smith, `have you noticed` how slow the product details page is lately?

**Smith**: Yeah, I did. I checked the logs, looks like we’re hitting the database for every request. It’s a pretty `expensive operation`.

**Roger**: Exactly. I think we should introduce some caching to `reduce latency`.

**Smith**: Agreed. Maybe we can cache the `data fragment` for product `specs`. It rarely changes.

**Roger**: Good idea. Should we go with a cache-aside strategy?

**Smith**: That works. We can check the cache first and only hit the DB if it’s `missing`.

**Roger**: And to prevent `stale data`, maybe `set a TTL of` 5 minutes?

**Smith**: Sounds good. We could also invalidate the cache manually when a product is updated.

**Roger**: Right. Also, some of those price calculations involve a `slow function call`, we should cache that too.

**Smith**: Yep. Let’s add Redis into the mix and `track the cache keys` by product ID.

**Roger**: Perfect. I’ll write the caching layer and set up the fallback to DB.

**Smith**: Awesome. Let’s deploy it to staging and test the `load time`.

---

### Vocabulary

|  |  |  |
| --- | --- | --- |
| hit ... (the database) | data fragment | have you noticed...? |
| stale data | reduce latency | set a TTL of |
| slow function call | Expensive operation | track the cache keys |
| load time | (product) specs | (something) missing |

**🔹 hit (the database)**  
To make a request to the database to retrieve or update data.  
*Example: "We hit the database every time a user loads the page."*

**🔹 data fragment**  
A small piece or section of data, often used to refer to part of a larger dataset.  
*Example: "We only need to cache the data fragment for the product description."*

**🔹 have you noticed...?**  
A phrase used to bring attention to something that may have changed or needs observation.  
*Example: "Have you noticed how slow the page has become?"*

**🔹 stale data**  
Outdated information stored in cache that may no longer reflect the current state.  
*Example: "We need to refresh the cache regularly to avoid serving stale data."*

**🔹 reduce latency**  
To decrease the delay between a request and its response.  
*Example: "Caching will help reduce latency and improve user experience."*

**🔹 set a TTL of**  
To assign a Time-To-Live (TTL), meaning how long a cached item stays valid.  
*Example: "We can set a TTL of 5 minutes for product info."*

**🔹 slow function call**  
A function that takes a long time to execute, often due to complex logic or external dependencies.  
*Example: "That price calculation is a slow function call — let's cache the result."*

**🔹 expensive operation**  
An operation that consumes a lot of time, memory, or processing power.  
*Example: "Fetching the entire product list is an expensive operation."*

**🔹 track the cache keys**  
To monitor and manage the identifiers used to store and retrieve cached items.  
*Example: "We should track the cache keys using the product ID."*

**🔹 load time**  
The amount of time it takes for a web page or resource to fully appear for the user.  
*Example: "We want to improve the load time of the product details page."*

**🔹 (product) specs**  
Short for specifications — technical or descriptive details of a product.  
*Example: "The product specs include dimensions, weight, and materials."*

**🔹 (something) missing**  
When something expected is not present or found.  
*Example: "If the data is missing in the cache, we’ll fetch it from the database."*

---

## Exercises

### Vocabulary

Choose the best option that matches the meaning or usage of each expression.

---

**1\. What does it usually mean when you “hit the database”?**  
A) Back up the database manually  
B) Update the user interface  
C) Make a request to the database  
D) Delete a record permanently

**2\. What is a “data fragment”?**  
A) A file stored in the recycle bin  
B) A piece of a larger set of data  
C) A network protocol  
D) A type of error message

**3\. “Have you noticed...?” is a way to:**  
A) Ask for permission  
B) Report a technical failure  
C) Request a password change  
D) Bring attention to a change or issue

**4\. What is “stale data”?**  
A) Fresh data from the API  
B) Data that is no longer valid or updated  
C) Data stored in a CSV file  
D) Data still loading

**5\. To “reduce latency” means to:**  
A) Add more logging  
B) Decrease the response time  
C) Increase CPU usage  
D) Remove all caching

**6\. What does “set a TTL of” 10 minutes mean?**  
A) Set a timer to delete the database  
B) Configure how long the cache remains valid  
C) Trigger a file transfer  
D) Make the page load slower

**7\. A “slow function call” typically:**  
A) Uses less memory  
B) Is unrelated to performance  
C) Takes a long time to execute  
D) Is only used in testing

**8\. An “expensive operation” in programming usually involves:**  
A) High cost in time or system resources  
B) External user authentication  
C) Currency conversion logic  
D) Buying additional software

**9\. To “track the cache keys” means to:**  
A) Encrypt cache data  
B) Monitor and manage how data is cached and retrieved  
C) Generate database indexes  
D) Secure passwords

**10\. What does “load time” refer to in a web app?**  
A) Server downtime  
B) Time it takes for a page or component to fully appear  
C) Memory usage of a background job  
D) Frequency of user sign-ins

**11\. “Product specs” typically include:**  
A) Customer email addresses  
B) Marketing slogans  
C) Technical details about a product  
D) Billing rates

**12\. When “something is missing” in a cache layer, it means:**  
A) The user’s session expired  
B) The item was not found in the expected storage  
C) A full database reset occurred  
D) The server restarted unexpectedly

---

### Fill-in-the blanks

Complete each sentence with the correct word or expression from the list below:

**Word Bank**:  
hit the database • data fragment • have you noticed • stale data • reduce latency • set a TTL of • slow function call • expensive operation • track the cache keys • load time • product specs • missing

---

1. To avoid unnecessary queries, the system first checks the cache before it needs to \_\_\_\_\_\_\_\_\_\_.
    
2. If you only need the title and price, cache that small \_\_\_\_\_\_\_\_\_\_ instead of the whole product object.
    
3. \_\_\_\_\_\_\_\_\_\_ how long the homepage takes to display lately?
    
4. We need to refresh the cache often, or users will see \_\_\_\_\_\_\_\_\_\_ that’s no longer accurate.
    
5. Using a CDN can help us \_\_\_\_\_\_\_\_\_\_ for users far from the server.
    
6. Let’s \_\_\_\_\_\_\_\_\_\_ 15 minutes so the cache doesn’t grow too stale.
    
7. That tax calculation runs every time and takes 2 seconds — definitely a \_\_\_\_\_\_\_\_\_\_.
    
8. Pulling all records with joins on 5 tables? That’s an \_\_\_\_\_\_\_\_\_\_ we should avoid frequently.
    
9. We should \_\_\_\_\_\_\_\_\_\_ by product ID to easily invalidate or refresh specific entries.
    
10. The \_\_\_\_\_\_\_\_\_\_ of our blog page increased after we added more third-party scripts.
    
11. The engineer asked for the \_\_\_\_\_\_\_\_\_\_ so she could double-check dimensions and compatibility.
    
12. If the data is \_\_\_\_\_\_\_\_\_\_ in the cache, we’ll fetch it directly from the backend.
    

---

### Reading comprehension

**1\. Why are Roger and Smith discussing caching strategies?**  
A) They want to upgrade the server  
B) The product details page is loading slowly  
C) They need to store user passwords  
D) They’re planning to delete the product table

**2\. What type of data do they decide to cache first?**  
A) User profiles  
B) Search queries  
C) Product specs  
D) Shopping cart contents

**3\. What strategy do they plan to use for caching?**  
A) Full-page caching  
B) Write-through caching  
C) Cache-aside (lazy loading)  
D) No-cache strategy

**4\. How do they plan to deal with stale data?**  
A) Never cache anything  
B) Use a CDN  
C) Manually update the cache and set a TTL  
D) Disable database access

**5\. Which tool do they mention for implementing the caching layer?**  
A) PostgreSQL  
B) Redis  
C) MongoDB  
D) Elasticsearch

---

## Homework

### Role play

**Instructions**:  
Work with a partner and create a short dialog (10–14 lines) between two software engineers discussing how to improve the performance of an API or web page. Be sure to include **at least 8** of the following words or phrases from the **Word Bank** in your conversation.

Word Bank: hit the database • data fragment • have you noticed • stale data • reduce latency • set a TTL of • slow function call • expensive operation • track the cache keys • load time • product specs • missing

---

### Life experience

Reflect on your own experiences in software development or system design. Answer the following questions based on situations similar to the dialog and vocabulary you’ve learned:

**1\. Have you ever worked on a system or application where performance was an issue?**  
What was causing the slow load time, and how did you or your team try to reduce latency?  

**2\. Can you recall a time when using cached data caused problems due to it being stale?**  
How did you detect it, and what did you do to prevent it from happening again?

  
**3\. Have you ever used tools like Redis or Memcached to avoid hitting the database repeatedly?**  
What kind of data or function calls did you cache, and what was the impact on performance?

  
**4\. In your projects, have you ever needed to track cache keys or set a TTL for cached items?**  
Why was this important in your system, and how did you manage invalidation or expiration?  

---

## Done

---
