Daily DSA and System Design Journal - 2

I

I.K

Guest
Hello, I'd decided to tackle DSA questions on LeetCode and learn a new concept about System Design daily (via the System Design Roadmap on roadmap.sh)and this is DAY 2:

First, System Design​


I began with another new System Design Concept: Performance vs. Scalability

Okay, so these terms get thrown around a lot in system design discussions. They're related, but definitely not the same thing. Think of it like this: you can have a super-fast sports car (high performance) that can only carry two people (low scalability). Or, you can have a bus (high scalability) that's not exactly winning any races (lower performance).

Performance: How Fast Is It?

Performance is all about speed and efficiency. It's a measure of how quickly your system responds to requests and how much resources it consumes while doing it.

Key metrics here include:

  1. Latency: How long does it take to get a response? (Think: ping time)
  2. Throughput: How many requests can the system handle in a given time period? (Requests per second - RPS)
  3. Resource Utilization: How much CPU, memory, and network bandwidth are you using?

You can improve performance through:

  1. Optimizing Code: Writing more efficient algorithms and data structures.
  2. Caching: Storing frequently accessed data in memory for faster retrieval.
  3. Database Optimization: Indexing, query optimization, and choosing the right database for the job.
  4. Load Balancing: Distributing traffic across multiple servers to prevent bottlenecks.

Scalability: How Well Does It Grow?

Scalability, on the other hand, is about how well your system can handle an increasing amount of traffic or data. Can your system handle 10x, 100x, or even 1000x the load without falling over or experiencing a significant performance degradation?

Key considerations for scalability:

  1. Horizontal Scaling: Adding more machines to your system. (Think: adding more servers to your web farm). This is generally preferred for scalability.
  2. Vertical Scaling: Upgrading the hardware on a single machine (more CPU, more RAM). This has limits.
  3. Statelessness: Designing your application so that each request can be handled independently by any server. This is crucial for horizontal scaling.
  4. Data Partitioning (Sharding): Breaking your data into smaller chunks and distributing them across multiple databases.

The Key Difference:

Performance is about optimizing what you already have to make it run faster.
Scalability is about designing your system to handle more load in the future.

Example Time!

Imagine you have a simple web application that displays a list of products.

Performance: You might improve performance by caching the product list in memory, so you don't have to query the database every time.
Scalability: You might improve scalability by adding more web servers behind a load balancer, so you can handle more users simultaneously. You might also shard your product database if it gets too large.

Why This Matters

Understanding the difference between performance and scalability is crucial for designing systems that are both fast and resilient. You need to think about how your system will perform under different load conditions and how you can scale it to meet future demands.

My Thoughts

I found it helpful to think of performance as a local optimization (making one part of the system faster) and scalability as a global property (designing the whole system to handle more load). It's definitely something I'll be keeping in mind as I continue learning about system design!

Now onto the DSA LeetCode Challenges​


Alright, time to switch gears and get those coding muscles working! Today's LeetCode victim (in a good way!) was an easy-level challenge: 9. Palindrome Number.

Now, I know what you might be thinking: "Palindrome? That's like, Intro to Programming 101." And you're not wrong! But sometimes it's good to revisit the basics, solidify your understanding, and focus on writing clean, readable code. Plus, it's a good warm-up for the brain.

It took me about an hour to solve, which I'm perfectly okay with. I'm not trying to break any speed records here. I'm prioritizing understanding, testing edge cases, and writing code that I'll be happy to look at six months from now.

Here are a few notes I jotted down during the process:

  1. String Conversion is Handy: I used str(x) to convert the integer to a string. It's a simple but essential technique.
  2. Python's Slicing is Slick: s[::-1] is such a concise way to reverse a string in Python! I love how readable it is. [::-1] means "start from the end and move backwards". Seriously, Python's string manipulation is one of the things that keeps me coming back.
  3. Palindrome Check: s == s[::-1] elegantly checks if the string is the same forwards and backwards.

My Takeaways:

Even though it was an "easy" problem, I still got something out of it. I reinforced my understanding of string manipulation in Python and practiced writing clean, well-tested code. It's a reminder that even simple problems can be valuable learning opportunities.

Let's Connect!


I plan to keep this daily learning journey going for as long as possible. It definitely helps to know there are people out there reading and maybe even learning along with me! So please, if you're finding this helpful or interesting, give it a follow, retweet, share, and let's chat about it in the comments! Your support really does make a difference.

Thanks for reading!


Continue reading...
 


Join 𝕋𝕄𝕋 on Telegram
Channel PREVIEW:
Back
Top