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.
- Custom TCP Server: Built from the ground up to handle raw TCP connections efficiently.
- In-Memory Key-Value Store: Provides basic
Set,Get, andDeleteoperations for string data. - Concurrency: Utilizes Go's goroutines and
sync.WaitGroupto 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
/healthendpoint to monitor server status. - Panic Recovery: Includes basic recovery for panics within connection handlers to prevent server crashes.
To get this server up and running on your local machine, follow these steps:
- Clone the Repository:
git clone https://github.com/SaranHiruthikM/performant-tcp-server.git
- Navigate to the Project Directory:
cd performant-tcp-server - Run the Server:
You can run the server directly:
Or build an executable:
go run main.go
You should seego build -o server . ./serverServer started on port, 8080in your console.
This project doesn't require any specific environment variables to run.
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, 80801. Set a key-value pair:
curl -X POST -d '{key:"myKey",value:"myValue"}' http://localhost:8080/set2. Get a value by key:
curl -X GET -d '{key:"myKey"}' http://localhost:8080/get
# Output: myValue3. Delete a key-value pair:
curl -X DELETE -d '{key:"myKey"}' http://localhost:8080/delete4. Check server health:
curl http://localhost:8080/health
# Output (empty body, 200 OK status)http://localhost:8080
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/setResponse:
(Empty body, HTTP/1.1 200 OK)
Errors:
500 Internal Server Error: If a server-side panic occurs during processing.
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/getResponse:
(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.
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/deleteResponse:
(Empty body, HTTP/1.1 200 OK)
Errors:
500 Internal Server Error: If a server-side panic occurs during processing.
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/healthResponse:
(Empty body, HTTP/1.1 200 Status OK)
Errors:
500 Internal Server Error: If a server-side panic occurs during processing.
| Technology | Description |
|---|---|
| Go | The primary language for the server logic. |
We welcome contributions to this project! If you have suggestions for improvements or new features, please feel free to:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature-name). - Make your changes.
- Commit your changes (
git commit -m 'Add new feature'). - Push to the branch (
git push origin feature/your-feature-name). - Open a Pull Request.
Please ensure your code adheres to Go's standard formatting and style guidelines.