Skip to main content

50 posts tagged with "system-design"

View all tags

What are the use cases for key-value caching?

· 3 min read

The essence of KV Cache is to reduce data access latency. For example, it transforms the O(logN) read/write and complex queries on a database that is expensive and slow into O(1) read/writes on a medium that is fast but also costly. There are many strategies for cache design, with common ones being read-through/write-through (or write-back) and cache aside.

The typical read/write ratio for internet services ranges from 100:1 to 1000:1, and we often optimize for reads.

In distributed systems, these patterns represent trade-offs between consistency, availability, and partition tolerance, and the specific choice should be based on your business needs.

General Strategies

  • Read
    • Read-through: A cache layer is added between clients and databases, so clients do not access the database directly but instead access it indirectly through the cache. If the cache is empty, it updates from the database and returns the data; if not, it returns the data directly.
  • Write
    • Write-through: Clients first write data to the cache, which then updates the database. The operation is considered complete only when the database is updated.
    • Write-behind/Write-back: Clients first write data to the cache and receive a response immediately. The cache is then asynchronously updated to the database. Generally, write-back is the fastest.
    • Write-around: Clients write directly to the database, bypassing the cache.

Cache Aside Pattern

Use the Cache Aside pattern when the cache does not support read-through and write-through/write-behind.

Reading data? If the cache hits, read from the cache; if it misses, read from the database and store in the cache. Modifying data? First modify the database, then delete the cache entry.

Why not update the cache after writing to the database? The main concern is that two concurrent database write operations could lead to two concurrent cache updates, resulting in dirty data.

Does using Cache Aside eliminate concurrency issues? There is still a low probability of dirty data occurring, especially when reading from the database and updating the cache while simultaneously updating the database and deleting the cache entry.

Where to Place the Cache?

  • Client side,
  • Distinct layer,
  • Server side.

What to Do If the Cache Size Is Insufficient? Cache Eviction Strategies

  • LRU - Least Recently Used: Keeps track of time and retains the most recently used items, evicting those that have not been used recently.
  • LFU - Least Frequently Used: Tracks usage frequency, retaining the most frequently used items and evicting the least frequently used ones.
  • ARC: Performs better than LRU by maintaining both recently used (RU) and frequently used (FU) items, while also recording the history of recently evicted items.

Which Cache Solution Is the Best?

Facebook TAO

What Can You Discuss in a Soft Skills Interview?

· 3 min read

Why Should We Value Soft Skills?

Because your job can be taken by someone with strong soft skills.

Americans have excellent speaking abilities, as their elementary education emphasizes expression, leading to articulate communication. In equal circumstances, even if Chinese individuals have better technical skills, job opportunities can still be snatched away by Americans. This is not about racial discrimination; it’s a matter of self-expression ability.

For instance, Indians have a strong presence in the U.S., especially in the management of high-tech companies, where the influence of Chinese individuals is far less. This is also due to the Indians' exceptional storytelling abilities. Although their English pronunciation may not be standard, they are willing to speak up and often get to the point. Consequently, we often see an Indian manager overshadowing several Chinese employees who may be technically superior. We often mock Indians for their “PPT governance,” but their storytelling ability is something to take note of.

This illustrates that the soft skills of “free artistry” are a shortcoming for contemporary Chinese individuals.

The Essence of an Interview is to Answer the Following Three Questions

  1. Can you do it or not?
  2. Do you want to do it or not?
  3. Are you a good fit or not?

How to Answer These Three Questions?

The five discussion points in an interview.

  1. Adversity. It’s not about how big the difficulties are, but how you overcame them. You need to prove that you were not only not defeated by adversity but became stronger. Ideally, downplay significant challenges with an optimistic tone. Also, take a moment to express gratitude to those who helped you during tough times, making it clear that you are a grateful person.

  2. Influence. All communication issues are essentially leadership issues, and all leadership issues are fundamentally communication issues. If you are good at persuading others, it indicates you possess inherent leadership qualities.

  3. Technical Proficiency. What stories can showcase your technical skills?

  4. Fit. When the FBI used to interview candidates, they liked to ask what books applicants had read. Candidates would list numerous titles, but what the FBI really wanted to hear was that they had read Tom Clancy's spy novels. For a while, anyone who mentioned reading Clancy's novels had a higher chance of being hired. Eventually, this insider information leaked, and then everyone started saying the same thing, making that tactic ineffective.

  5. Achievements. Compared to others, do you have any standout qualities? This is your opportunity to boast about past accomplishments. Achievements don’t necessarily have to be actual work experience.

On a larger scale, even U.S. presidential campaigns follow this pattern. Obama would say, “My father was an immigrant, and he abandoned my mother. I grew up in a single-parent household as a Black man, and it was tough for me… but none of that matters now; I am optimistic and strong.” Trump would say, “I have worked on this project, that project, and this project, and now I want to undertake a major project that benefits America.”

How to Prepare for These Five Discussion Points?

  • Try more, experience failures, and enrich your life experiences;
  • Engage with more people to practice your communication and organizational skills;
  • Learn some technical skills and master practical tools;
  • Be good at research to understand what is happening in your field; seek opportunities to achieve results that make you stand out.