Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Performant TCP Key-Value Server

Overview

This project gives you a super-fast way to store and get back little pieces of information. Think of it like a personal vault for your data that you can talk to directly over the internet, making sure things are saved and retrieved really quickly. It solves the problem of needing a very lightweight and direct way to manage simple data without the overhead of more complex systems.

Features

  • Custom TCP Server: Built from the ground up to handle raw TCP connections efficiently.
  • In-Memory Key-Value Store: Provides basic Set, Get, and Delete operations for string data.
  • Concurrency: Utilizes Go's goroutines and sync.WaitGroup to handle multiple client connections concurrently.
  • Graceful Shutdown: Listens for interrupt signals (Ctrl+C) to ensure clean server termination.
  • Basic Request Parsing: Parses raw HTTP-like requests, including method, path, headers, and body.
  • Health Check Endpoint: A simple /health endpoint to monitor server status.
  • Panic Recovery: Includes basic recovery for panics within connection handlers to prevent server crashes.

Getting Started

Installation

To get this server up and running on your local machine, follow these steps:

  1. Clone the Repository:
    git clone https://github.com/SaranHiruthikM/performant-tcp-server.git
  2. Navigate to the Project Directory:
    cd performant-tcp-server
  3. Run the Server: You can run the server directly:
    go run main.go
    Or build an executable:
    go build -o server .
    ./server
    You should see Server started on port, 8080 in your console.

Environment Variables

This project doesn't require any specific environment variables to run.

Usage

Once the server is running, you can interact with it using curl or any other tool that can make raw TCP requests. The server listens on localhost:8080.

Start the server:

go run main.go
# Output: Server started on port, 8080

1. Set a key-value pair:

curl -X POST -d '{key:"myKey",value:"myValue"}' http://localhost:8080/set

2. Get a value by key:

curl -X GET -d '{key:"myKey"}' http://localhost:8080/get
# Output: myValue

3. Delete a key-value pair:

curl -X DELETE -d '{key:"myKey"}' http://localhost:8080/delete

4. Check server health:

curl http://localhost:8080/health
# Output (empty body, 200 OK status)

API Documentation

Base URL

http://localhost:8080

Endpoints

POST /set

Brief description of what this endpoint does: Stores a new key-value pair or updates an existing one in the in-memory store.

Request:

{key:"yourKey",value:"yourValue"}

Note: The server expects the body as a raw string in this format, not strict JSON.

Example with curl:

curl -X POST -d '{key:"temperature",value:"25C"}' http://localhost:8080/set

Response:

(Empty body, HTTP/1.1 200 OK)

Errors:

  • 500 Internal Server Error: If a server-side panic occurs during processing.

GET /get

Brief description of what this endpoint does: Retrieves the value associated with a specified key.

Request:

{key:"yourKey"}

Note: The server expects the body as a raw string in this format, not strict JSON.

Example with curl:

curl -X GET -d '{key:"temperature"}' http://localhost:8080/get

Response:

(Body contains the value, HTTP/1.1 200 OK)
# Example: 25C

Errors:

  • 404 Not Found: If the key does not exist in the store.
  • 500 Internal Server Error: If a server-side panic occurs during processing.

DELETE /delete

Brief description of what this endpoint does: Removes a key-value pair from the store based on the provided key.

Request:

{key:"yourKey"}

Note: The server expects the body as a raw string in this format, not strict JSON.

Example with curl:

curl -X DELETE -d '{key:"temperature"}' http://localhost:8080/delete

Response:

(Empty body, HTTP/1.1 200 OK)

Errors:

  • 500 Internal Server Error: If a server-side panic occurs during processing.

GET /health

Brief description of what this endpoint does: A simple health check to determine if the server is responsive.

Request: (No body required)

Example with curl:

curl http://localhost:8080/health

Response:

(Empty body, HTTP/1.1 200 Status OK)

Errors:

  • 500 Internal Server Error: If a server-side panic occurs during processing.

Technologies Used

Technology Description
Go The primary language for the server logic.

Contributing

We welcome contributions to this project! If you have suggestions for improvements or new features, please feel free to:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature-name).
  3. Make your changes.
  4. Commit your changes (git commit -m 'Add new feature').
  5. Push to the branch (git push origin feature/your-feature-name).
  6. Open a Pull Request.

Please ensure your code adheres to Go's standard formatting and style guidelines.

Go

About

Simple Mock Redis TCP Server from Scratch

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages