Social Network Development
A social network is one of the technically complex web platforms: relationship graphs between users, real-time notifications and chat, algorithmic feed, scalable media storage, content moderation. Building "VKontakte from scratch" is an unrealistic task, but niche social networks (network for a specific profession, hobby, community) are quite feasible projects.
Social Relationship Graph
Two types of relationships:
- Symmetric (friendship): User A is friends with User B → both see each other's posts
- Asymmetric (follow): User A follows User B → A sees B's posts, not the other way around
Storing the relationship graph in a relational database:
CREATE TABLE follows (
follower_id BIGINT REFERENCES users(id),
following_id BIGINT REFERENCES users(id),
created_at TIMESTAMP,
PRIMARY KEY (follower_id, following_id)
);
CREATE INDEX ON follows (following_id); -- for query "who follows X"
With large user count (>10M), store the graph in specialized Graph DB (Neo4j, Amazon Neptune) or Redis with SSCAN.
Publication Feed
Fan-out on write (push model): on post publish — write to each follower's feed. Reading feed is very fast (pre-computed). Downside: if user has 1M followers — need 1M records.
Fan-out on read (pull model): feed computed on read from all followed posts. Slower on read, simpler write.
Hybrid (Facebook/Instagram approach): regular users — fan-out on write. "Celebrity" with millions of followers — fan-out on read. Threshold determined dynamically.
# Redis ZSET for user feed
ZADD feed:{user_id} {timestamp} {post_id}
ZREVRANGE feed:{user_id} 0 19 -- last 20 posts
Real-time Notifications
WebSocket (Socket.io or native WebSocket) for: new notification, new chat message, new post comment.
Architecture with horizontal scaling — Redis Pub/Sub: any server publishes event to channel, all servers with WebSocket connections receive and deliver to subscribers.
Media Storage
Photos and videos — in object storage (S3/Cloudflare R2). Processing:
- Photos: resize → multiple thumbnails (150, 400, 800px) → WebP conversion
- Videos: transcoding via FFmpeg or cloud (Cloudflare Stream, Mux)
Processing — async via queue. User sees "processing", after completion — notification.
Algorithmic Feed
Simple ranking algorithm (not chronological):
score = likes_count * W1
+ comments_count * W2
+ shares_count * W3
+ recency_decay * W4
+ affinity_score * W5 -- how close author is to user
affinity_score — frequency of user interactions with author (likes, comments, profile views).
Content Moderation
- Hash-filtering: PhotoDNA / PDQ hash to detect known CSAM and illegal content
- ML-moderation: NSFW image detection (Google Vision Safe Search API, NudeNet)
- Text moderation: toxicity detection (Perspective API, OpenAI Moderation API)
- User reports → queue for moderators → decision (remove / keep / warn)
Privacy
Profile and post privacy settings: public, friends only, private. GDPR: data export, account deletion (soft delete with full deletion after 30 days).
Timeline
MVP (profiles, follows, posts with photos, comments, feed, basic notifications): 4–6 months. Full platform with video, chat, algorithmic feed, moderation, mobile apps: 10–18 months.







