How sumit-22/social-graph works
1. Repository shape
- This is a polyglot monorepo with a small Next.js frontend at the root (app/, public/, lib/) and a larger Java/Spring Boot backend under backend/socialgraph/.
- The backend is split into independently deployable microservices, each with its own pom.xml, Dockerfile, config, and tests.
2. Frontend boundary
- The root app/ directory contains the UI shell (layout.tsx, page.tsx) and a dedicated app/seed/page.tsx, which likely serves as a demo or data-seeding entrypoint.
- The frontend appears to be thin: it presents the app and probably talks to the backend services over HTTP; no heavy client-side domain logic is visible in the tree.
3. User service
- backend/socialgraph/user-service owns authentication, user profiles, and follow relationships.
- It persists the social graph in Neo4j (Neo4jConfig, FollowNode, FollowRepository) and uses JWT for auth (JwtTokenProvider, JwtAuthenticationFilter, SecurityConfig).
- It also has a rate limiting filter and a logging aspect, which are architectural concerns around abuse protection and observability.
4. Feed ingestor
- backend/socialgraph/feed-ingestor is the write path for posts.
- It stores posts in a relational database through PostRepository/Post and publishes a PostEvent to Kafka via KafkaProducerConfig.
- This service is also JWT-protected, so authenticated users create posts through it rather than directly touching storage or the stream.
5. Feed ranker
- backend/socialgraph/feed-ranker is the asynchronous processing layer.
- FeedRankerConsumer consumes Kafka post events, resolves follower relationships from Neo4j, computes ranking, and writes results into Redis as the precomputed read model.
- ResilienceConfig suggests this service is designed for retry/backoff/fault tolerance around downstream dependencies.
6. Feed API
- backend/socialgraph/feed-api is the read path for personalized feeds.
- FeedController serves feed requests by reading ranked identifiers from Redis and enriching them from the post store.
- This service is separately secured with JWT and includes OpenAPI config, indicating it is the primary client-facing API for feed retrieval.
7. Core data flow
- The main runtime flow is: user authenticates and establishes follows in the user service; a post is created in the ingestor; the ingestor writes the post and emits a Kafka event; the ranker consumes the event, looks up followers, and updates Redis; the feed API then serves a fast ranked feed from Redis-backed state.
- This is a classic event-driven split between write amplification and read optimization.
8. State and storage boundaries
- Neo4j is the graph source of truth for social relationships.
- PostgreSQL holds post/user-oriented durable records for transactional access.
- Redis acts as a low-latency serving layer for ranked feeds.
- Kafka is the decoupling mechanism that turns post creation into asynchronous downstream ranking.
9. Shared security pattern
- Each service has its own JWT plumbing rather than a single shared auth gateway.
- The user service includes the most additional protection, notably rate limiting, while the other services focus on verifying authenticated requests before allowing reads/writes.
10. Operational packaging
- The repo is set up for containerized deployment: each backend module has a Dockerfile, and there are docker-compose.yml and docker-compose.test.yml files at the backend root.
- Helper scripts like startup.sh and health-check.sh indicate the system is intended to be brought up and validated as a coordinated stack.
11. Testing and quality
- Each service has its own tests in src/test, including controller and security tests.
- backend/socialgraph/load-tests contains Scala-based load testing, which aligns with the project’s low-latency feed goal.
- GitHub Actions workflows cover build/test and code quality, showing CI is part of the architecture, not an afterthought.
12. Observability and docs
- The backend includes monitoring/prometheus.yml, so metrics scraping is explicitly supported.
- OpenAPI configuration exists in at least the user and feed API services, which helps define and expose service contracts.
- Log artifacts under logs/ and the logging aspect in the user service suggest production-style operational visibility.
13. Seed/demo data
- public/data/*.sample.json, scripts/generate-seed.ts, and lib/seed/generator.ts indicate a local/demo data generation path.
- The app/seed page likely provides a UI entry for seeding or showcasing sample content, supporting repeatable demos and testing.
14. How to diagram it
- Draw four service boxes: user service, feed ingestor, feed ranker, feed API.
- Connect user service to Neo4j; feed ingestor to PostgreSQL and Kafka; feed ranker to Kafka, Neo4j, and Redis; feed API to Redis and PostgreSQL.
- Place the Next.js frontend above them as the client-facing entrypoint, and show Docker/Compose, Prometheus, CI, and load tests as supporting platform layers around the services.
Main entry points: feed-api Feed API · docker-compose.yml Docker stack · user-service User service · FeedRankerConsumer.java Ranker consumer
Components 23
Frontend
Next.js UI and local demo seeding entrypoints
- Next.js app · Root Next.js frontend entrypoint and page layout
app/page.tsx - Seed page · UI entrypoint for seeding or showcasing sample data
app/seed/page.tsx
Backend services
Spring Boot microservices for identity, writes, async ranking, and feed reads
- User service · Authentication, profiles, and follow relationships
backend/socialgraph/user-service - Auth layer · Login, token issuing, request authentication, and rate limiting
backend/socialgraph/user-service/src/main/java/com/social/user/security - Social graph · Users and follow edges stored in Neo4j-backed repositories
backend/socialgraph/user-service/src/main/java/com/social/user/graph - Feed ingestor · Authenticated post creation and event publication
backend/socialgraph/feed-ingestor - Post store · Transactional post persistence and write-side data access
backend/socialgraph/feed-ingestor/src/main/java/com/social/ingestor/repo - Event producer · Emits post events for downstream async processing
backend/socialgraph/feed-ingestor/src/main/java/com/social/ingestor/config/KafkaProducerConfig.java - Feed ranker · Consumes post events and builds ranked feed state
backend/socialgraph/feed-ranker - Ranker consumer · Consumes post events and computes recipient ranking
backend/socialgraph/feed-ranker/src/main/java/com/social/ranker/service/FeedRankerConsumer.java - Resilience · Retry/backoff and downstream protection for ranking flow
backend/socialgraph/feed-ranker/src/main/java/com/social/ranker/config/ResilienceConfig.java - Feed API · Serves personalized feeds to clients
backend/socialgraph/feed-api - Feed controller · Client-facing feed retrieval endpoint
backend/socialgraph/feed-api/src/main/java/com/social/feed/controller/FeedController.java - Feed security · Request authentication for feed reads
backend/socialgraph/feed-api/src/main/java/com/social/feed/security
Platform
Shared storage, messaging, packaging, observability, and validation
- Neo4j · Source of truth for users and follow relationships
- PostgreSQL · Durable post and transactional records
- Kafka · Decouples post creation from ranking updates
- Redis · Precomputed ranked feed state for low-latency reads
- Docker stack · Dockerfiles and compose files for local or staged deployment
backend/socialgraph/docker-compose.yml - Prometheus · Metrics scraping and operational monitoring
backend/socialgraph/monitoring/prometheus.yml - CI workflows · Build, test, and code quality pipelines
.github/workflows/build-and-test.yml - Load tests · Performance validation for feed latency and throughput
backend/socialgraph/load-tests/src/test/scala/com/social/LoadTest.scala - Seed data · Sample JSON data and seed generation scripts
public/data/posts.sample.json
Connections 27
- Next.js app → User service: client auth · Frontend interacts with the identity service for sign-in and social actions
- Next.js app → Feed API: read feed · Frontend requests personalized feeds from the API
- Seed page → Seed data: uses · Seed/demo page is backed by sample content and generation assets
- User service → Auth layer: contains · Authentication and rate limiting live inside the user service
- User service → Social graph: contains · Follow graph persistence is part of the user service
- Social graph → Neo4j: stores · User relationships are persisted in Neo4j
- Feed ingestor → Post store: contains · Write-side persistence is handled by the ingestor
- Feed ingestor → Event producer: contains · The ingestor publishes post events after writes
- Post store → PostgreSQL: stores · Posts are written to the relational database
- Event producer → Kafka: publishes · Post creation emits Kafka events
- Feed ranker → Ranker consumer: contains · Ranking is driven by an event consumer
- Feed ranker → Resilience: contains · Fault tolerance is configured in the ranker
- Ranker consumer → Kafka: consumes · Ranking reacts to post events from Kafka
- Ranker consumer → Neo4j: reads follows · Follower relationships are resolved from Neo4j
- Ranker consumer → Redis: writes feed · Computed rankings are stored for fast serving
- Feed API → Feed controller: contains · Feed retrieval is exposed through the controller
- Feed API → Feed security: contains · JWT verification protects feed reads
- Feed controller → Redis: reads · Ranked feed identifiers are loaded from Redis
- Feed controller → PostgreSQL: enriches · Feed items are enriched from durable post records
- Docker stack → User service: deploys · Compose and Docker packaging run the service stack
- Docker stack → Feed ingestor: deploys · Compose and Docker packaging run the service stack
- Docker stack → Feed ranker: deploys · Compose and Docker packaging run the service stack
- Docker stack → Feed API: deploys · Compose and Docker packaging run the service stack
- Prometheus → User service: scrapes · Prometheus supports service-level observability
- Prometheus → Feed API: scrapes · Prometheus supports service-level observability
- CI workflows → Docker stack: validates · CI covers build, test, and quality gates for the stack
- Load tests → Feed API: measures · Load tests target the feed-serving path