Skip to content

Latest commit

 

History

25 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Key-Value HTTP Storage Service (Erlang)

This project implements a lightweight in-memory key-value storage service exposed through an HTTP API. The system allows clients to perform basic operations such as storing, retrieving, and deleting values associated with keys.

The service is implemented in Erlang, follows a simple RESTful design and communicates using JSON over HTTP.

The system is designed under the following assumptions: it runs as a single-node service and prioritizes fast concurrent read and write operations using an in-memory storage model. All data is stored at runtime and is not persisted to disk.

System Architecture

The application follows a three‑layer design:

Layer Module Responsibility
HTTP Layer http_handler.erl Acts as the system entry point, exposing a RESTful HTTP API. It translates external HTTP requests into internal operations and ensures consistent communication through JSON and standard HTTP status codes.
Storage Interface storage_interface.erl Defines a bridge between the HTTP layer and the storage implementation. It provides a stable contract for data operations, ensuring that higher-level logic remains decoupled from storage-specific details.
Storage Backend storage_ets.erl Provides the concrete implementation of the storage contract using Erlang Term Storage (ETS). It manages the in-memory data table and performs all data operations while supporting concurrent access.

Request Flow Summary

  1. Client sends HTTP request (GET, PUT, DELETE)
  2. http_handler processes request and extracts parameters
  3. storage_interface forwards operation to backend
  4. storage_ets executes ETS operation
  5. Result is returned back through the layers
  6. HTTP response is generated

Implementation Notes

The system is implemented using the following technologies:

  • HTTP Layer: Cowboy is used as the HTTP server to handle incoming requests and route them to the application logic. JSON encoding and decoding is performed using JSX.
  • Storage Backend: ETS is used as the in-memory storage engine, providing fast concurrent access to key-value data.

API Documentation

The service exposes a RESTful HTTP API for managing key-value pairs. All requests and responses are encoded in JSON, and the service uses standard HTTP status codes to indicate success or failure.

1. Retrieve a Value

Retrieves the current value associated with a given key.

HTTP Method: GET
Endpoint: /keys/:key
Request Body: None

Responses

Status Code Meaning Response Body
200 OK Key exists and value was retrieved successfully { "key": "<key>", "value": <stored_value> }
404 Not Found Key does not exist in the table { "error": "key not found" }

2. Store or Update a Value

Stores or updates the value associated with a given key.

HTTP Method: PUT
Endpoint: /keys/:key
Request Body: { "value": <any JSON value> }

Responses

Status Code Meaning Response Body
200 OK Value successfully stored or updated { "key": "<key>", "value": <stored_value> }
400 Bad Request Invalid request body (empty body, invalid JSON, or missing value field) { "error": "<reason>" }

3. Delete a key

Deletes the value associated with a given key.

HTTP Method: DELETE
Endpoint: /keys/:key
Request Body: None

Responses

Status Code Meaning Response Body
200 OK Key successfully deleted { "key": "<key>" }
404 Not Found Key does not exist in the table { "error": "key not found" }

Project Structure

src/
├── http_handler.erl              # HTTP layer 
├── storage_interface.erl         # Storage abstraction layer (API between HTTP and backend)
├── storage_ets.erl               # ETS in-memory key-value storage implementation
│
├── http_service_app.erl          # OTP application entry point 
├── http_service_sup.erl          # Supervisor (placeholder for future supervised processes; currently has no children)
└── http_service.app.src          # Application resource file (metadata, dependencies)
│
scripts/
│
└── test.sh                       # Integration test script for API validation

How to Run

Prerequisites

  • Erlang/OTP installed
  • rebar3 build tool installed

Compilation

From the project root directory, compile the project using:

rebar3 compile

Start an Erlang shell:

rebar3 shell

Test the API

./test.sh

About

In-memory key-value storage service implemented in Erlang and exposed through an HTTP API. It supports basic create, read, and delete operations on keys and is designed to handle concurrent requests efficiently.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages