A lightweight, in-memory feature store API built with Go and Gin. Designed for fast prototyping of machine learning pipelines, online inference, or ML infrastructure experiments.
- π§ Create and retrieve ML features via REST API
- π In-memory storage (no external DB required)
- π Thread-safe with
sync.RWMutex - β‘ Fast and easy to deploy
| Method | Endpoint | Description |
|---|---|---|
| POST | /features |
Create or update a feature |
| GET | /features/:entity_id/:name |
Retrieve a specific feature |
| File/Folder | Description |
|---|---|
main.go |
Entry point |
go.mod |
Go module configuration |
models/ |
Feature model definition |
ββ feature.go |
Struct definitions for Feature |
storage/ |
In-memory store with mutex |
ββ store.go |
Store implementation |
handlers/ |
API logic (set/get feature) |
ββ feature_handler.go |
Handlers for feature APIs |
routers/ |
Route setup |
ββ routers.go |
Router initialization |
{
"entity_id": "2025-06-01",
"name": "temperature",
"value": 28.5
}By implementing an in-memory store with sync.RWMutex, I learned the importance of using Lock() and Unlock() (or RLock()/RUnlock()) to protect shared data like a Go map.
Without locks:
- Concurrent reads/writes can cause data races
- Go maps will panic on simultaneous writes
With proper locking:
RLock()allows safe concurrent readsLock()serializes writesdefer Unlock()ensures clean, reliable code
This is essential for building safe, concurrent systems.
This kind of API can be useful in many ways:
- π§ Online inference cache for low-latency model serving
- π§ͺ Rapid prototyping of ML pipelines or REST APIs
- π§° Local development/testing without needing Redis or a full database
- π¦ Temporary store in data pipelines
- π Edge ML applications with memory-constrained environments
This project taught me how to structure a Go-based API server using a modular, maintainable pattern:
-
models/ β data schema
-
handlers/ β API logic
-
routers/ β route wiring
-
storage/ β business logic (store/retrieve)
-
main.go β entry point
Following this modular structure prepares the codebase for future improvements like adding Redis, databases, or Docker.