How jason810496/dcard-advertisement-api works
Overall Project Type and Purpose
• That this is a back‑end API service dedicated to advertisement creation and query.
• Read-heavy nature, with performance targets (e.g., 1000 RPS at minimum, with design enhancements to hit 10,000 RPS) and the use of caching tiers to ensure low-latency response times.
• That additional deployment and CI/CD aspects (Docker, Kubernetes deployments, Terraform infra, GitHub Actions workflows) support the overall operation.
Main Components
a. Ingress / API Gateway:
– Mark an “Ingress” component that represents the external entry point (load balancer or gateway).
b. Stateless Application Servers (AP Cluster):
– Represent multiple API server instances (e.g., AP1, AP2, AP3) in a “Stateless AP Cluster” that handle public and admin API calls.
– Inside each API server block, indicate the local in-memory cache, which is refreshed by background goroutines. You might also show that one or more processes incorporate extra “BG Goroutines” for local cache refresh.
c. Caches:
– Represent the “Local Cache” on each API instance (illustrating the use of fastcache or gin-cache for caching by URI).
d. Database Tier:
– Show a “Postgres Primary” and a “Postgres Replica” (or a cluster block with a line denoting WAL replication) for persistent storage of advertisement data.
e. Background / Scheduling Components:
– Include a “Corn Job” (or Scheduler) component that periodically enumerates hotspot parameter combinations and updates both the Redis cache and local cache.
– Optionally, show the “Generator” component (from cmd/generator) if it is used to pre-populate or refresh data.
f. CI/CD and Deployment/Infra:
Relationships and Data Flow
– (1) When the request is “cache hit”: the API consults the local cache and/or Redis.
– (2) When the local or Redis cache is “missed”: the API falls back to querying the Postgres database (primary or replica).
• That advertisement creation (admin API) directs writes into the Postgres primary, while read queries come from both caches and replicas.
Architectural Patterns and Technologies
• That the system is built with Golang.
• Mention the use of caching strategies (e.g., “Cache by URI” via gin-cache, multi-layer cache pre-heating using Lua scripts for atomic updates).
• Use labels or callouts to show that the architecture was designed to avoid cache avalanche scenarios by pre-computing hot combinations.