Skip to content

Repository files navigation

car

An @imqueue RPC microservice that serves the car catalog — the makes, models and body types customers pick from when registering a vehicle.

On start it downloads the public US EPA FuelEconomy vehicle dataset, extracts and parses it, and keeps the catalog in memory for fast lookups. It never speaks HTTP; every method is exposed over the @imqueue/rpc Redis message queue and consumed by the gateways (api, api-rest).

About the tutorial

This repo is one piece of the imqueue-sandbox tutorial — a complete car-wash booking app built from independent RPC microservices that communicate over a Redis-backed message queue.

Repo Role Store
user Customer accounts & their garage MongoDB
auth Login, JWT issuing & revocation Redis
car Car catalog (makes / models / types) in-memory
time-table Washing reservations & schedule PostgreSQL
api GraphQL gateway orchestrating the fleet
api-rest REST/OpenAPI gateway over the same fleet
web-app React front-end on api (GraphQL/Relay)
web-app-rest React front-end on api-rest (REST)

The backend services are transport-agnostic: two interchangeable gateways and two independent front-ends prove the same fleet can be fronted by completely different API styles without changing a single service.

RPC methods

Exposed by the Car service (src/Car.ts) via @expose():

Method Signature Description
version () Running service name / version / repository.
brands () Sorted list of manufacturer (brand) names.
list (brand, fields?, sort='model', dir='asc') Cars for a given brand, sorted and de-duplicated.
fetch (id | id[], fields?) One car by id, or many when given an array of ids.

A catalog entry is { id, make, model, type, years[] }, where type is a normalized size class (mini / midsize / large) and id is a stable hash of make + model + type.

How the catalog is built

  • On cold start the service downloads the dataset zip from CARS_DATA_URL, extracts it with adm-zip, and streams the CSV into an in-memory index (brands, id → car).
  • A per-host Redis lock (SET … NX EX 30) elects a single downloader so that multiple workers on the same machine share one download and the local data/ directory.
  • The dataset is refreshed on a 24-hour interval; Redis is used only for the update lock — the catalog itself is never cached in Redis.

Configuration

Environment variables (loaded from an optional .env via process.loadEnvFile()):

Variable Default Purpose
CARS_DATA_URL EPA vehicles.csv.zip URL Source of the car catalog dataset.
IMQ_REDIS localhost:6379 Redis endpoint(s) for the RPC message queue and the update lock.

The first start needs outbound network access to fetch the dataset (~20 MB). Subsequent starts reuse the extracted CSV under data/.

Running

Development mode (rebuilds and restarts on change):

npm run dev

Production mode:

npm start

Both start the service under the imqueue label car. Requires Redis at IMQ_REDIS.

License

ISC License

About

Cars data service for @imqueue project

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages