Skip to main content

Welcome to CryptoPulse

CryptoPulse is a production-ready NestJS service that provides cryptocurrency price lookups with intelligent request batching, persistence, and enterprise-grade authentication.

What is CryptoPulse?

CryptoPulse is designed to efficiently handle high-volume cryptocurrency price queries while minimizing external API calls. When multiple requests ask for the same coin’s price around the same time, the service intelligently batches them together and serves all requests from a single upstream call to CoinGecko.

Key Features

Intelligent Request Batching

Automatically groups same-coin requests to reduce API calls. Batches wait up to 5 seconds but flush immediately when 3 requests accumulate.

PostgreSQL Persistence

Every successful price fetch is stored in PostgreSQL with full historical data available via paginated endpoints.

Multi-Instance Ready

Uses Redis for coordination, allowing horizontal scaling with multiple API instances working in sync.

JWT Authentication

Secure bearer token authentication protects all price endpoints with configurable expiration.

Rate Limiting

Built-in throttling with separate limits for global requests and login attempts, backed by Redis.

Interactive API Docs

Full Swagger/OpenAPI documentation at /docs with request examples and error code references.

How It Works

The batching architecture follows a simple but powerful flow:
1

Client Request

A client calls GET /v1/price/:coinId with a valid JWT token
2

Request Grouping

The service adds the request to a per-coin waiter group, tracked in Redis
3

Smart Flush

The batch flushes when either:
  • 3 pending requests accumulate (threshold), OR
  • 5 seconds elapse (batch window)
4

Single API Call

One CoinGecko API call is made and the result is persisted to PostgreSQL
5

Fan-Out Response

The price is returned to all waiting requests simultaneously

Architecture Highlights

Tech Stack

  • Framework: NestJS with Fastify for high performance
  • Database: PostgreSQL with TypeORM for structured data
  • Cache/Coordination: Redis (ioredis) for distributed batching and throttling
  • Authentication: JWT tokens via @nestjs/jwt
  • Documentation: OpenAPI/Swagger at /docs
  • Testing: Jest with comprehensive unit and e2e coverage

Design Principles

CryptoPulse prioritizes efficiency and reliability. By batching requests intelligently, it can reduce external API calls by up to 90% in high-traffic scenarios while maintaining sub-second response times.
The service requires Redis to be available for batching coordination. If Redis becomes unavailable, the service returns 503 Service Unavailable to prevent inconsistent behavior.

API Endpoints

CryptoPulse exposes a clean REST API:
EndpointMethodDescription
/auth/loginPOSTAuthenticate and receive JWT token
/v1/price/:coinIdGETGet current price (with batching)
/v1/price/:coinId/historyGETGet historical prices with pagination

Use Cases

  • Cryptocurrency Dashboards: Display real-time prices for multiple coins efficiently
  • Trading Bots: Query prices with minimal API overhead and rate limit exposure
  • Portfolio Trackers: Historical price data with date range filtering and pagination
  • Price Alerts: Monitor specific coins with persistent price history
  • Analytics Platforms: Build reports on price trends over time

What’s Next?

Quickstart

Get CryptoPulse running with Docker in under 5 minutes

Installation

Detailed installation guide for local development and production

API Reference

Complete API documentation with examples and error codes

Configuration

Learn about environment variables and customization options

Build docs developers (and LLMs) love