How ppy/osu-server-spectator works
Project type and purpose
• This is a backend web service (ASP.NET Core) that handles real-time “spectator” data for osu! matches.
• It exposes multiple SignalR hubs for multiplayer events, metadata broadcasting, score uploading, logging, and spectator streams.
• It persists data to MySQL (via Dapper), optionally to AWS S3 or local file storage, and integrates with other osu! web services over HTTP.
File structure
• Top-level directories:
• osu.Server.Spectator – the main server project
• osu.Server.Spectator.Tests – unit/integration tests
• SampleMultiplayerClient & SampleSpectatorClient – example .NET client apps
• Key modules inside osu.Server.Spectator:
• Hubs/… – SignalR hubs (MetadataHub, MultiplayerHub, SpectatorHub, LoggingHub, StatefulUserHub)
• Services/… – business logic, shared interop with osu-web
• Database/… – Dapper wrappers, factory, data models
• Storage/… – IScoreStorage implementations (FileScoreStorage, S3ScoreStorage)
• Authentication, Extensions, GracefulShutdownManager, ConcurrentConnectionLimiter
• Configuration & deployment files: Dockerfile, appsettings.json, CI workflows.
README for additional insights
• Environment variables define ports, Redis, MySQL, S3 credentials, Sentry/Datadog, replay storage options, and shared-interop settings.
• The service is designed to plug into a full osu! server stack and interacts with the osu-web instance for shared interop.
A. Clients
• Game Clients (Multiplayer spectators & broadcasters)
• SampleMultiplayerClient & SampleSpectatorClient (for testing)
B. Load Balancer / API Gateway (optional)
• Routes WebSocket (SignalR) and HTTP (shared interop) traffic to the server cluster
C. osu-Server-Spectator Service (ASP.NET Core app)
1. SignalR Hubs Layer (Presentation)
– MetadataHub (broadcasts build counts, daily challenges)
– MultiplayerHub (match events, queues, room management)
– SpectatorHub (real-time score streams)
– LoggingHub (client logs)
– StatefulUserHub (user-state subscriptions)
2. Services Layer (Application logic)
– SharedInterop service (HTTP calls to osu-web)
– ConcurrentConnectionLimiter, ChatFilters, ScoreUploader, etc.
3. Data Access Layer
– DatabaseFactory & DatabaseAccess (Dapper)
– EntityStore (in-memory caches)
4. Storage Layer
– MySQL database (osu-web schema)
– Redis (interop messaging, optional)
– Replay storage (local file system or AWS S3)
5. Cross-cutting concerns
– Authentication (JWT bearer)
– GracefulShutdownManager
– Dependency Injection (ServiceCollectionExtensions)
– Logging (Sentry, Datadog via DD_AGENT_HOST)
D. External Systems
• osu-web HTTP API (shared interop domain)
• MySQL (DB_HOST: DB_PORT)
• Redis (REDIS_HOST)
• AWS S3 (REPLAYS_BUCKET)
• Monitoring & Error Tracking (Datadog, Sentry)
Relationships & data flow
• Within the server: Hubs → call into Services → call into Data Access → talk to MySQL or Redis
• SpectatorHub & ScoreUploader → write replay frames → local FS or S3
• Services → HTTP → osu-web (shared interop)
• Logging & metrics emitted to Datadog/Sentry via DI-injected logging pipeline
• GracefulShutdownManager coordinates shutdown across hubs and background tasks
Architectural patterns & principles
• Layered architecture (Presentation → Application → Data → Infrastructure)
• Real-time pub/sub via SignalR hubs
• Dependency injection for loose coupling (ISharedInterop, IScoreStorage, IDatabaseAccess)
• Single monolithic service with logical separation (no microservices)
• Configuration via environment variables for twelve-factor compliance
• Containerization (Dockerfile)