This project is a high-performance RESTful service for managing and analyzing financial data in near real-time. It is built in Go and uses fasthttp for its high-performance HTTP server.
The service supports two HTTP endpoints:
POST /add_batch: Adds a batch of trading data for a specific symbol.GET /stats: Retrieves statistical analysis of recent trading data for a symbol.
The service uses an in-memory storage solution designed for high-performance reads and writes. The core of the storage engine is a sliding window algorithm implemented with deques, which allows for the calculation of min, max, average, and variance in amortized O(1) time.
- Go (version 1.24.5 or later)
-
Clone the repository:
git clone <repository-url> cd neptune-task
-
Install dependencies:
go mod tidy
-
Run the service:
make run
The service will start on http://localhost:8080.
-
URL:
/add_batch -
Method:
POST -
Body:
{ "symbol": "BTCUSD", "values": [68000.5, 68001.0, 68000.0] }
- URL:
/stats - Method:
GET - Query Parameters:
symbol(string): The financial instrument's identifier.k(integer): An integer from 1 to 8, specifying the number of last1e{k}data points to analyze.
- Example:
GET /stats?symbol=BTCUSD&k=2
The project includes comprehensive benchmarks to measure the maximum Requests Per Second (RPS) for different scenarios:
Quick benchmark run:
make benchmark-quickStandard benchmarks:
make benchmarkDetailed performance analysis:
make benchmark-detailed- AddBatch - Measures RPS for
/add_batchendpoint - GetStats - Measures RPS for
/statsendpoint
make help # Show all available commands
make build # Build the application
make run # Run the server
make test # Run all tests
make deps # Install dependencies
make fmt # Format code
make lint # Run linter
make clean # Clean build artifactsRun the test suite:
make test-
Storage Engine (
pkg/storage/)- Sliding window implementation
- Deque-based min/max tracking
- Welford's algorithm for rolling variance
- Pre allocated arrays
-
API Layer (
api/)- FastJSON for efficient JSON parsing
- Fasthttp for high-performance HTTP
- Input validation and error handling
-
Data Structures (
pkg/storage/deque/)- Custom deque implementation for min/max tracking
- Memory-efficient circular buffer