Skip to content

An MVP tool for visualizing API latency using percentile analysis (p50, p95, p99) instead of averages. Built with Node.js, TypeScript, PostgreSQL, and React.

Notifications You must be signed in to change notification settings

devleo10/delayt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

API Latency Visualizer

An MVP tool for visualizing API latency using percentile analysis (p50, p95, p99) instead of averages. Built with Node.js, TypeScript, PostgreSQL, and React.

License Node TypeScript

🎯 Why Percentiles Matter

The Problem with Averages:

  • Averages hide outliers. An API with 99 requests at 10ms and 1 request at 10 seconds has an average of ~200ms, which doesn't reflect the user experience.
  • Real-world latency follows a long-tail distribution where a small percentage of requests take much longer.

Why p95 and p99 Matter:

  • p50 (median): Half of your requests are faster than this. Good baseline, but doesn't show worst-case.
  • p95: 95% of requests are faster than this. This is what most users experience. Critical for SLA monitoring.
  • p99: 99% of requests are faster than this. Shows your worst-case performance for almost all users.

Example: If your API has:

  • Average: 50ms
  • p95: 500ms
  • p99: 2000ms

This tells you that while most requests are fast (average 50ms), 5% of users experience 500ms+ latency, and 1% experience 2+ seconds. This is critical information that averages hide.

πŸ—οΈ Architecture

Clear separation of concerns:

  • Runner (src/runner.ts): Sends 50 sequential requests per endpoint, measures latency using high-resolution timers
  • Storage (src/storage.ts): Saves raw request data to Postgres
  • Analytics (src/analytics.ts): Computes percentiles and payload bucket analysis

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • PostgreSQL 12+
  • npm or yarn

Installation

  1. Clone the repository:
git clone https://github.com/devleo10/delayt.git
cd delayt
  1. Install backend dependencies:
npm install
  1. Install frontend dependencies:
cd client
npm install
cd ..
  1. Set up PostgreSQL:
CREATE DATABASE latency_visualizer;
  1. Configure environment variables (optional): Create a .env file in the root directory:
DB_HOST=localhost
DB_PORT=5432
DB_NAME=latency_visualizer
DB_USER=postgres
DB_PASSWORD=postgres
PORT=3001
  1. Run database migration:
npm run build
npm run migrate

Running the Application

  1. Start the backend server:
npm run dev
  1. Start the frontend (in a new terminal):
npm run client
# or
cd client && npm start
  1. Open your browser: Navigate to http://localhost:3000

πŸ“– Usage

  1. Add API endpoints:

    • Enter endpoints in the text area, one per line
    • Format: METHOD URL [PAYLOAD for POST]
    • Examples:
      GET https://api.github.com/users/octocat
      POST https://jsonplaceholder.typicode.com/posts {"title": "test"}
      
  2. Run tests:

    • Click "Run Tests" - this sends exactly 50 sequential requests per endpoint
    • Results are stored in Postgres
  3. View analytics:

    • Table shows: endpoint, method, p50, p95, p99, avg payload size
    • Endpoints are ranked by p95 (slowest first)
    • Slow endpoints (p95 > 1000ms) are highlighted
    • Chart shows payload size vs latency for POST requests

✨ Features

  • βœ… Exactly 50 sequential requests per endpoint
  • βœ… High-resolution latency measurement (nanosecond precision using process.hrtime.bigint())
  • βœ… Records: endpoint, method, latency_ms, request_size_bytes, response_size_bytes, status_code
  • βœ… Percentile analysis (p50, p95, p99) - no averages as primary metric
  • βœ… Payload size bucketing for POST requests
  • βœ… Request timeouts (30 seconds)
  • βœ… No retries (failures are logged and recorded)
  • βœ… Single-page React UI with table and chart visualization
  • βœ… Slow endpoint highlighting

πŸ”Œ API Endpoints

POST /api/test

Submit endpoints to test.

Request:

{
  "endpoints": [
    {"url": "https://api.example.com", "method": "GET"},
    {"url": "https://api.example.com/data", "method": "POST", "payload": {"key": "value"}}
  ]
}

Response:

{
  "success": true,
  "message": "Tests completed"
}

GET /api/analytics

Get percentile statistics and payload buckets.

Response:

{
  "percentileStats": [
    {
      "endpoint": "https://api.example.com",
      "method": "GET",
      "p50": 45.2,
      "p95": 120.5,
      "p99": 250.8,
      "avg_payload_size": 0
    }
  ],
  "payloadBuckets": [
    {
      "bucket_min": 0,
      "bucket_max": 100,
      "p95": 85.3,
      "count": 150
    }
  ]
}

πŸ“ Project Structure

.
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ runner.ts          # Request execution and latency measurement
β”‚   β”œβ”€β”€ storage.ts         # Postgres data persistence
β”‚   β”œβ”€β”€ analytics.ts       # Percentile and bucket calculations
β”‚   β”œβ”€β”€ server.ts          # Express API server
β”‚   β”œβ”€β”€ types.ts           # TypeScript type definitions
β”‚   └── migrations/
β”‚       └── migrate.ts     # Database schema
β”œβ”€β”€ client/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.tsx        # React frontend
β”‚   β”‚   β”œβ”€β”€ App.css        # Styles
β”‚   β”‚   └── types.ts       # Frontend type definitions
β”‚   └── package.json
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ .gitignore
└── README.md

πŸ› οΈ Development

Build

npm run build

Run migrations

npm run migrate

Development mode

# Backend (with hot reload)
npm run dev

# Frontend (with hot reload)
npm run client

πŸ“Š Database Schema

CREATE TABLE api_requests (
  id SERIAL PRIMARY KEY,
  endpoint VARCHAR(500) NOT NULL,
  method VARCHAR(10) NOT NULL,
  latency_ms NUMERIC(10, 2) NOT NULL,
  request_size_bytes INTEGER NOT NULL,
  response_size_bytes INTEGER NOT NULL,
  status_code INTEGER NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

⚠️ Limitations (By Design - MVP Scope)

  • No authentication
  • No live monitoring
  • No distributed tracing
  • No background agents
  • Sequential requests only (not parallel)
  • Fixed 50 requests per endpoint
  • No historical comparison

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“ License

MIT License - see LICENSE file for details

πŸ‘€ Author

devleo10

πŸ™ Acknowledgments

About

An MVP tool for visualizing API latency using percentile analysis (p50, p95, p99) instead of averages. Built with Node.js, TypeScript, PostgreSQL, and React.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published