Đang tải...

How I Built A Real-time Streaming Market Data with .NET and ReactJS

09/05/2026
4 phút đọc
How I Built A Real-time Streaming Market Data with .NET and ReactJS
![Architecture of RealMarketAPI](https://images.viblo.asia/513fabb5-9801-4991-946a-c9dcbb5de844.png) **Last month** I shared how I turned a side project into a SaaS. Today, I’m opening the hood and ...

Architecture of RealMarketAPI

Last month I shared how I turned a side project into a SaaS. Today, I’m opening the hood and showing you the actual architecture, tech decisions, and lessons learned.


📋 Table of Contents


I. Why I Built This

I got tired of:

  • Paying $200–$800/month for APIs that go down during high volatility
  • Inconsistent latency (especially WebSocket)
  • Terrible historical data quality
  • Vendors suddenly changing pricing or throttling indie developers

So I decided to build my own — focused on reliability, transparency, and developer experience.


II. High-Level Architecture

Here’s the current system:

Architecture of RealMarketAPI


III. Core Components Explained

1. RealMarketAPI (Entry Point)

  • Simple REST + WebSocket gateway
  • Handles authentication (JWT + API keys)
  • Rate limiting & usage tracking

2. Auth Service

  • Validates tokens
  • Checks subscription tier
  • Rejects invalid requests early

3. RealMarketServices (The Brain)

This is where the magic happens. It’s split into three main services:

  • Ticker Service – Ultra-low latency price updates
  • Stream Service – WebSocket broadcaster (using Redis Pub/Sub)
  • Historical Service – Candle & tick data delivery

4. Data Storage Strategy

  • Redis → Hot short-term ticker data + Pub/Sub
  • PostgreSQL + TimescaleDB → Long-term candles and relational data
  • Candles DB → Dedicated time-series optimized storage

5. Data Ingestion

  • Multiple workers fetch from various Brokers/Exchanges
  • Retry logic + circuit breakers + fallback sources
  • Data is normalized into a unified format

6. RealMarketBots (Bonus Layer)

One of my favorite parts:

  • Scrapes news & trends using RSS + SerpAPI
  • Generates content summaries with Gemini
  • Sends Telegram alerts
  • Auto-publishes to Facebook and X

NextJS

IV. Tech Stack

Backend: C# .NET

using FastEndpoints;
using RealTimeMarketAPI.Core.Modules.TickerModule.Handlers;
using RealTimeMarketAPI.Infrastructure.Models;

namespace RealTimeMarketAPI.Core.Modules.TickerModule.Endpoints
{
 public class GetCandlesEndpoint : Endpoint<GetCandlesRequest, ListResult<GetCandlesResponse>>
 {
 public override void Configure()
 {
 AllowAnonymous();
 Get("candle");
 Version(1);
 }

 public override async Task HandleAsync(GetCandlesRequest req, CancellationToken ct)
 {
 var result = await req.ExecuteAsync(ct);
 await Send.OkAsync(result, cancellation: ct);
 }
 }
}

Stack using: FastEndpoints, PostgreSQL, Redis

Frontend: Next.js NextJS

  • Real-time: Redis + custom WebSocket server
  • Database: PostgreSQL
  • Observability: Datadog Datadog for monitoring

V. Biggest Challenges So Far

  • WebSocket Scale – Maintaining thousands of concurrent connections with low latency is hard.
  • Data Consistency – Different exchanges have different timestamp formats and precision.
  • Cost Control – Exchange API fees + bandwidth can explode quickly.
  • Testing – You can’t easily replay real market conditions.

VI. What’s Next

  • TradingView widget
  • Official SDKs (Python, Node.js, Go)
  • More symbols & exchanges
  • Dedicated enterprise nodes

VII. Final Words

Building a market data api taught me one important lesson: Reliability beats features.

Most users don’t need 10,000 symbols. They need 3 symbols that actually work at 3 AM when Bitcoin crashes.

That’s what I’m optimizing for.

You can check it out here: RealMarketAPI


Let me know in the comments:

  • What market data pain point do you have?
  • Would you use this for algo trading, dashboards, or AI agents?

I read every comment

📚 Nguồn: Viblo

Chia sẻ bài viết

Cần tư vấn?

Liên hệ với chúng tôi để được hỗ trợ

Liên hệ ngay

Bài viết liên quan

Đừng để Queue Worker "đột tử": Giải phẫu DB::disableQueryLog() chống Memory Leak trong Laravel
09/05/2026

Đừng để Queue Worker "đột tử": Giải phẫu DB::disableQueryLog() chống Memory Leak trong Laravel

Chào anh em cộng đồng Viblo! Hôm nay chúng ta sẽ cùng mổ xẻ một vấn đề mà tôi cá là 90% anh em làm backend Laravel sớm muộn gì cũng sẽ gặp phải khi hệ thống ...

Đọc thêm
Nghiệp vụ Checkout COD: Không chỉ là một nút bấm - Tư duy xử lý "vạn đơn" cho Backend
09/05/2026

Nghiệp vụ Checkout COD: Không chỉ là một nút bấm - Tư duy xử lý "vạn đơn" cho Backend

### 1. Mở đầu: "Cạm bẫy" của sự đơn giản Trong thanh toán online, chúng ta dựa vào kết quả trả về từ Gateway (Paypal, VNPay...). Với COD, "hợp đồng" thanh toán ...

Đọc thêm
Tooltips trong Material 3 Jetpack Compose: nhỏ nhưng rất “có võ”
09/05/2026

Tooltips trong Material 3 Jetpack Compose: nhỏ nhưng rất “có võ”

Tooltip là một trong những UI component nhỏ nhưng mang lại trải nghiệm rất tốt nếu dùng đúng cách. Trong Jetpack Compose với Material 3, tooltip đã được hỗ trợ chí...

Đọc thêm

Bắt đầu dự án của bạn

Hãy để Flash Dev đồng hành cùng bạn

Liên hệ ngay