How pneum4/megaarticle works
1. This is a Gradle multi-module Java/Spring Boot repository organized as a microservice system for a high-traffic bulletin board. The codebase is split into shared libraries under common/ and independently deployable services under service/, plus a separate swagger-gateway module for API documentation aggregation.
2. The architecture is strongly write/read separated. The write-side services own the authoritative data for articles, comments, likes, and views. The read-side services (article-read and hot-article) consume domain events and maintain optimized projections for fast querying.
3. Shared foundation modules provide the cross-service contracts and infrastructure:
- common/event defines the event envelope, event types, and payloads for article/comment lifecycle, like/unlike, and view events.
- common/data-serializer centralizes serialization of event/data payloads.
- common/snowflake provides distributed ID generation.
- common/outbox-message-relay implements the outbox relay pattern, with relay, coordinator, repository, and publisher components for reliable event publication.
4. service/article is the article write model. It exposes ArticleController, persists Article and BoardArticleCount, and contains request/response DTOs plus pagination logic. This service is the source of truth for article CRUD and article-count updates.
5. service/comment manages threaded comments and supports two versions of the comment model (Comment/CommentV2) with CommentPath for deep nesting. It has separate controllers and services for the two versions, plus an ArticleCommentCount projection to track comment totals.
6. service/like owns article likes. It stores individual like records and aggregated ArticleLikeCount, exposing a dedicated controller/service for like and unlike actions. Like state is maintained here rather than embedded in the article service.
7. service/view is the view-counting subsystem. It includes a distributed-lock repository and a backup repository, which indicates contention-sensitive counting with a persistence fallback/repair path. ArticleViewCountBackUpProcessor suggests asynchronous reconciliation of view counters after transient failures or heavy write load.
8. service/article-read is the primary read-optimized API. It has its own controller, query repositories, and a service layer that assembles article read responses. It also calls out to ArticleClient, CommentClient, LikeClient, and ViewClient, so the read model is enriched from multiple source services rather than queried from a single monolith.
9. The article-read service also contains a custom cache subsystem (OptimizedCache, aspect, TTL, lock provider, manager, origin supplier), which is designed to reduce repeated read amplification and prevent cache stampedes on hot endpoints. This is a key performance boundary in the architecture.
10. service/hot-article is a separate ranking/read model for “hot” content. It consumes article/comment/like/view events, calculates scores with HotArticleScoreCalculator, updates rankings via HotArticleScoreUpdater, and serves them through HotArticleController. The supporting repositories track article creation time and per-signal counts needed for scoring.
11. Event propagation is the main integration path between services. Write-side services emit domain events through the shared event model and outbox relay; Kafka is the asynchronous backbone used by consumer modules in article-read and hot-article. This gives eventual consistency between the authoritative write stores and the precomputed read stores.
12. swagger-gateway is not a business gateway in the request path; it is a documentation/Swagger aggregation module. Each service also has its own SwaggerConfig, which reinforces the independently deployable-service boundary.
13. The main infrastructure technologies that materially shape the architecture are Spring Boot, Kafka, Redis, and MySQL. Kafka carries cross-service events, Redis is used where low-latency coordination or buffering matters, and the services are designed to run separately, likely via Docker as noted in the README.
14. For an architecture diagram, the most important boundaries are: write services as system-of-record, common libraries as shared contracts/infrastructure, Kafka as the async event bus, and read/ranking services as event-driven projections optimized for query and aggregation.
Main entry points: article-read Article read · swagger-gateway Swagger gateway · article Article svc · event Event model
Components 18
Common libs
Shared contracts and infrastructure used by services
- Event model · Event envelope, types, and payloads for article, comment, like, and view changes
common/event - Serializer · Central payload serialization utilities
common/data-serializer - Snowflake · Distributed ID generation for services
common/snowflake - Outbox relay · Outbox relay, coordinator, repository, and publisher for reliable async publication
common/outbox-message-relay
Write services
System-of-record services for mutations and authoritative state
- Article svc · Authoritative article CRUD and board article counts
service/article - Article API · ArticleController entrypoint for article mutations and queries
service/article/src/main/java/pneum4/board/article/controller/ArticleController.java - Comment svc · Threaded comments with v1 and v2 models plus comment totals
service/comment - Like svc · Article like/unlike ownership and aggregated like counts
service/like - View svc · View counting with distributed locking and backup reconciliation
service/view
Read models
Event-driven projections and query-optimized APIs
- Article read · Read-optimized article API that assembles responses from multiple source services
service/article-read - Read cache · Optimized cache, lock provider, TTL, and origin supplier to prevent stampedes
service/article-read/src/main/java/pneum4/board/articleread/cache - Event consumer · Consumes article and comment events to update read projections
service/article-read/src/main/java/pneum4/board/articleread/consumer/ArticleReadEventConsumer.java - Read repos · Query models and repositories for article lists and board counts
service/article-read/src/main/java/pneum4/board/articleread/repository - Hot article · Event-driven hot content ranking and serving
service/hot-article - Score engine · Hot article score calculation and projection updates
service/hot-article/src/main/java/pneum4/board/hotarticle/service - Rank consumer · Consumes article, comment, like, and view events to refresh hot rankings
service/hot-article/src/main/java/pneum4/board/hotarticle/consumer/HotArticleEventConsumer.java - Hot repos · Ranking state, signal counts, and article creation time repositories
service/hot-article/src/main/java/pneum4/board/hotarticle/repository
Docs
Swagger aggregation and API documentation
- Swagger gateway · Aggregates service API docs without being in the business request path
swagger-gateway
Connections 31
- Article svc → Event model: publishes · Article lifecycle changes are emitted as shared domain events
- Comment svc → Event model: publishes · Comment lifecycle changes are emitted as shared domain events
- Like svc → Event model: publishes · Like and unlike actions are emitted as shared domain events
- View svc → Event model: publishes · View events are emitted for downstream projections
- Article svc → Outbox relay: relays via · Write-side services use the outbox relay for reliable publication
- Comment svc → Outbox relay: relays via · Comment events are dispatched through the shared outbox pattern
- Like svc → Outbox relay: relays via · Like events are dispatched through the shared outbox pattern
- View svc → Outbox relay: relays via · View events are dispatched through the shared outbox pattern
- Article svc → Snowflake: ids · Distributed IDs support write-side entities
- Comment svc → Snowflake: ids · Distributed IDs support comment entities
- Like svc → Snowflake: ids · Distributed IDs support like entities
- View svc → Snowflake: ids · Distributed IDs support view entities
- Article read → Read cache: uses · Read API depends on the optimized cache boundary
- Article read → Read repos: queries · Read API assembles responses from projection repositories
- Article read → Event consumer: updates from · Event consumer keeps read projections current
- Article read → Article svc: fetches from · Read responses are enriched from article source service
- Article read → Comment svc: fetches from · Read responses are enriched from comment source service
- Article read → Like svc: fetches from · Read responses are enriched from like source service
- Article read → View svc: fetches from · Read responses are enriched from view source service
- Hot article → Rank consumer: updates from · Hot rankings are driven by Kafka event consumption
- Hot article → Score engine: calculates · Score engine computes ranking signals and updates
- Hot article → Hot repos: persists · Ranking projections are stored in dedicated repositories
- Hot article → Article svc: enriches from · Hot article responses can reference article source data
- Rank consumer → Event model: consumes · Consumes shared lifecycle and signal events from the event stream
- Event consumer → Event model: consumes · Consumes shared lifecycle and signal events from the event stream
- Swagger gateway → Article svc: documents · Aggregates service API documentation
- Swagger gateway → Comment svc: documents · Aggregates service API documentation
- Swagger gateway → Like svc: documents · Aggregates service API documentation
- Swagger gateway → View svc: documents · Aggregates service API documentation
- Swagger gateway → Article read: documents · Aggregates service API documentation
- Swagger gateway → Hot article: documents · Aggregates service API documentation