Skip to content

YSWFelicity/Online_Audiobook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Audiobook Platform

A microservices backend for an audiobook streaming platform, supporting on-demand audio playback, live broadcasts, in-app purchases, and full-text search. Built on Spring Cloud with event-driven communication and horizontally-scalable services.

Architecture

Ten domain-aligned microservices behind an API gateway, communicating over both synchronous (HTTP/REST) and asynchronous (Kafka) channels. Each service owns its database; cross-service queries go through declarative REST clients with circuit-breaker protection.

                      ┌──────────────┐
   clients ─────────► │ API Gateway  │  routing · CORS · rate limit
                      └──────┬───────┘
                             │
   ┌─────────────────────────┼─────────────────────────┐
   │                         │                         │
┌──▼──┐ ┌──────┐ ┌──────┐ ┌──▼──┐ ┌──────┐ ┌──────┐ ┌──▼──┐
│User │ │Album │ │Order │ │Pay  │ │Search│ │Live  │ │ ... │
└──┬──┘ └──┬───┘ └──┬───┘ └──┬──┘ └──┬───┘ └──┬───┘ └─────┘
   │       │        │        │       │        │
   └───────┴────────┴────────┴───────┴────────┘
            Kafka (events) · Redis (cache/locks)
            MySQL · MongoDB · Elasticsearch · Object Storage

Services

Service Port Responsibility
server-gateway 8500 API gateway, routing, CORS, global rate limiting
service-album 8501 Albums, tracks, audio upload pipeline
service-user 8503 User profiles, OAuth2 login, listening history
service-order 8504 Order lifecycle, inventory, idempotent state machine
service-account 8505 User wallet, virtual currency, transactions
service-payment 8506 Payment gateway integration, webhook verification
service-live 8507 Live streaming (RTMP ingest / HLS playback), WebSocket chat
service-comment 8508 Comments and replies (MongoDB)
service-dispatch 8509 Distributed scheduled jobs (indexing, expiry sweeps)
service-search 8502 Full-text search over albums and tracks
service-system 8510 Admin/back-office APIs

Tech Stack

Core

  • Java 17, Spring Boot 3.0.5, Spring Cloud 2022.0.2
  • Spring Cloud Gateway — API gateway
  • OpenFeign — declarative REST clients between services
  • Service discovery & centralized configuration (via Nacos)
  • Circuit breaker, rate limiting, and flow control (via Sentinel)

Data

  • MySQL 8 + MyBatis-Plus — relational persistence (per-service databases)
  • Redis + Redisson — caching, distributed locks, rate limiters
  • MongoDB — comments and other semi-structured data
  • Elasticsearch — full-text search and ranking

Async & Scheduling

  • Apache Kafka — event-driven communication (order events, search indexing, listening history)
  • XXL-Job — distributed task scheduling for batch jobs and timeouts

Media & Storage

  • S3-compatible object storage (MinIO) — audio file storage
  • Video-on-demand pipeline — transcoding, signed playback URLs, CDN delivery
  • Live streaming — RTMP ingest, HLS playback, real-time chat over WebSocket

Integrations

  • OAuth2-based third-party login — token exchange, signed JWTs
  • Payment gateway integration — signed webhook callbacks, idempotency keys, refund flow

API & Tooling

  • OpenAPI 3 / Swagger — interactive API documentation
  • Jackson — JSON serialization
  • HikariCP — connection pooling

Key Engineering Features

  • Idempotent payment flow — webhook signature verification, deduplication via Redis, automatic retries with exponential backoff
  • Event-driven order pipeline — order placement, payment confirmation, and inventory adjustments coordinated through Kafka topics
  • Distributed locks — Redisson-backed locks guard inventory deduction and seckill flows under concurrent load
  • Read-through caching — frequently accessed album/track data cached in Redis with explicit invalidation on writes
  • Async search indexing — album mutations publish to Kafka; the search service consumes and indexes into Elasticsearch, decoupling write paths from search availability
  • Signed playback URLs — short-lived signed URLs prevent unauthorized audio/video access

Project Structure

.
├── common/             Shared utilities (logging, Kafka helpers, security, etc.)
├── model/              Cross-service DTOs / VOs / entities
├── server-gateway/     Spring Cloud Gateway
├── service/            Business microservices (album, user, order, ...)
├── service-client/     Feign client interfaces for inter-service calls
└── Resource/           Nacos config templates (DEFAULT_GROUP/*.yaml)

Prerequisites

  • JDK 17
  • Maven 3.6+
  • MySQL 8.x
  • Redis
  • Nacos Server (for service discovery and config)
  • Apache Kafka
  • MongoDB
  • Elasticsearch 7.x+
  • MinIO (or any S3-compatible object store)
  • XXL-Job admin (optional, for scheduled jobs)

Install pinyin4j into your local Maven repo before building:

mvn install:install-file \
  -Dfile=/path/to/pinyin4j-2.5.0.jar \
  -DgroupId=com.belerweb \
  -DartifactId=pinyin4j \
  -Dversion=2.5.0 \
  -Dpackaging=jar

Configuration

All service configs are loaded from Nacos at startup. Templates live under Resource/DEFAULT_GROUP/ with <PLACEHOLDER> tokens — fill them in with your own credentials and import into your Nacos DEFAULT_GROUP namespace before starting services.

Note: Do not commit real credentials. The templates intentionally use placeholders for database passwords, third-party API keys, and host names.

Build & Run

# Build all modules
mvn clean install -DskipTests

# Start the gateway, then each service
cd server-gateway && mvn spring-boot:run
cd service/service-user && mvn spring-boot:run
# ... etc

Each service is an independent Spring Boot application; run only the services you need for local development.

API Documentation

Once a service is running, interactive OpenAPI docs are available at:

http://<host>:<service-port>/doc.html

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages