🍩
System Design: Zero to Hero
  • 👋About System Design Learning Journey
  • Contents
  • 1️⃣1. Fundamentals of System Design
    • 1.1. Introduction to System Design
    • 1.2. Basic Principles and Concepts
    • 1.3. Trade-offs in System Design
    • 1.4. Non-Functional Requirements in System Design
    • 1.5. Back-of-the-Envelope Calculations in System Design
    • 1.6. Mini-Project: Simple Key-Value Store in Go
Powered by GitBook
On this page
  • Project Overview
  • Project Requirements
  • Implementation Steps
  • Testing Your Implementation
  • Considerations
  • Extension Ideas
  1. 1. Fundamentals of System Design

1.6. Mini-Project: Simple Key-Value Store in Go

Previous1.5. Back-of-the-Envelope Calculations in System Design

Last updated 6 months ago

Project Overview

In this mini-project, you'll design and implement a simple key-value store in Go. This project will help you apply the concepts we've discussed, including basic system design principles, trade-offs, and non-functional requirements.

Project Requirements

  1. Implement basic CRUD (Create, Read, Update, Delete) operations for key-value pairs.

  2. Add simple persistence to disk.

  3. Implement basic error handling and logging.

  4. Consider and implement at least one aspect of scalability or performance optimization.

Implementation Steps

  1. Set up the project:

    • Create a new Go project.

    • Set up a basic directory structure.

  2. Implement in-memory storage:

    • Create a struct to represent your key-value store.

    • Implement methods for Get, Set, Update, and Delete operations.

  3. Add persistence:

    • Implement functions to save the key-value store to a file.

    • Implement functions to load the key-value store from a file.

    • Decide when to persist (e.g., after each write operation or at regular intervals).

  4. Implement error handling and logging:

    • Use Go's error handling mechanisms.

    • Implement basic logging to track operations and errors.

  5. Optimize for performance or scalability:

    • Consider implementing one of the following:

      • A simple cache to speed up frequent reads.

      • Concurrent access using Go's synchronization primitives.

      • A basic sharding mechanism to distribute keys.

  6. Write tests:

    • Implement unit tests for your CRUD operations.

    • Test error handling and edge cases.

Testing Your Implementation

  1. Functional testing:

    • Test each CRUD operation individually.

    • Test combinations of operations.

    • Verify that data persists after restarting the program.

  2. Error handling:

    • Test how your program handles invalid inputs.

    • Test scenarios like trying to read a non-existent key.

  3. Performance testing (if implemented):

    • Test how your store performs with a large number of keys.

    • If you implemented concurrency, test with multiple simultaneous operations.

  4. Persistence testing:

    • Verify that data is correctly saved to and loaded from disk.

    • Test scenarios like unexpected program termination.

Considerations

As you work on this project, keep in mind the system design principles we've discussed:

  • Modularity: How can you structure your code to be modular and easy to understand?

  • Trade-offs: What trade-offs are you making in your design decisions?

  • Non-functional requirements: How does your implementation address requirements like performance, reliability, and scalability?

Extension Ideas

If you finish the basic implementation and want to challenge yourself further, consider:

  1. Implementing a simple HTTP server to interact with your key-value store.

  2. Adding a time-to-live (TTL) feature for keys.

  3. Implementing a simple replication mechanism to store data on multiple "nodes".

Remember, the goal is to apply the concepts you've learned and gain practical experience. Don't worry about creating a production-ready system. Focus on understanding the design decisions you're making and their implications.

Good luck, and enjoy building your key-value store!

1️⃣