Skip to content

Nirvisha82/Reddit-clone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Reddit-like Engine and Simulator in Go

Go Version Proto Actor Actor Model Zipf Distribution

A high-performance, concurrent Reddit-like social platform simulator built with Go and the Proto Actor framework. The system models realistic user behavior using Zipf distribution for subreddit popularity and supports large-scale simulations with up to 100K users and 250K actions.

πŸš€ Features

  • πŸ—οΈ Actor-Based Architecture: Distributed system using Proto Actor framework
  • πŸ“Š Realistic User Modeling: Zipf distribution for authentic subreddit popularity simulation
  • ⚑ High Performance: Handles 100K+ users with 250K+ actions in under 3 minutes
  • πŸ”„ Concurrent Operations: Full async/await support for all user interactions
  • πŸ‘₯ Complete Social Features: Posts, comments, voting, direct messaging, and feeds
  • πŸ“ˆ Karma System: Dynamic reputation tracking with upvote/downvote mechanics
  • πŸ”Œ Connection Management: User online/offline status simulation
  • πŸ“± Real-time Feed: Personalized content feeds based on subscriptions
  • πŸ“Š Analytics: Comprehensive simulation statistics and user action tracking

πŸ› οΈ Tech Stack

Component Technology
Language Go 1.19+
Actor Framework Proto Actor
Concurrency Model Actor-based messaging
Distribution Zipf distribution for realistic modeling
Architecture Concurrent, event-driven

πŸ“ Project Structure

reddit-simulator/
β”œβ”€β”€ main.go              # Application entry point and configuration
β”œβ”€β”€ engine.go            # Core Reddit engine with all business logic
β”œβ”€β”€ simulator.go         # User behavior simulation and Zipf distribution
β”œβ”€β”€ models.go            # Data structures for users, posts, comments
β”œβ”€β”€ messages.go          # Actor message definitions and protocols
└── README.md           # Project documentation

πŸ”§ Installation & Setup

Prerequisites

  • Go 1.19 or higher
  • Proto Actor Go framework

Step 1: Clone Repository

git clone <repository-url>
cd reddit-simulator

Step 2: Install Dependencies

go mod init reddit-simulator
go get github.com/asynkron/protoactor-go/actor
go mod tidy

Step 3: Run Simulation

# Default simulation (30 users, 6 subreddits, 200 actions, 5 seconds)
go run .

# Custom parameters
go run . -users 10 -subreddits 3 -actions 100 -time 3

# Large-scale simulation
go run . -users 1000 -subreddits 50 -actions 5000 -time 30

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Main Thread   β”‚    β”‚   Actor System  β”‚    β”‚    Engine       β”‚
β”‚                 │────▢│                 │────▢│    Actor        β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                        β”‚
                                β–Ό                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Simulator     β”‚    β”‚   Message       β”‚    β”‚   Data Models   β”‚
β”‚   Actor         │◀───│   Passing       │────▢│                 β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”„ Command Line Options

Flag Default Description
-users 30 Maximum number of users to simulate
-subreddits 6 Maximum number of subreddits to create
-actions 200 Total number of simulation actions
-time 5 Simulation duration in seconds

Usage Examples

# Quick test run
go run . -users 5 -subreddits 2 -actions 50 -time 2

# Medium simulation
go run . -users 100 -subreddits 10 -actions 1000 -time 10

# Large-scale performance test
go run . -users 10000 -subreddits 100 -actions 25000 -time 60

🎯 Core Features

User Management

  • User Registration: Dynamic user creation during simulation
  • Connection Status: Online/offline state management
  • Karma System: Reputation tracking based on community interactions

Subreddit Operations

  • Create Subreddits: Dynamic community creation
  • Join/Leave: Flexible membership management
  • Zipf Distribution: Realistic popularity modeling

Content Management

  • Post Creation: Rich content posting to any subreddit
  • Nested Comments: Multi-level comment threading with replies
  • Voting System: Upvote/downvote mechanics affecting karma
  • Direct Messaging: Private user-to-user communication

Social Features

  • Personalized Feeds: Content from subscribed subreddits
  • Real-time Interactions: Concurrent user actions
  • Community Building: Organic subreddit growth patterns

πŸ“Š Karma System

The karma system models Reddit's reputation mechanics:

Karma Rules

  • +1 Karma: Per post creation
  • +1 Karma: Per comment on posts
  • +1 Karma: Per upvote received on content
  • -1 Karma: Per downvote received on content
  • Default Upvote: Authors automatically upvote their own posts

Calculation Formula

Total Karma = Posts Created + Comments Made + (Total Upvotes - Total Downvotes)

🎲 Zipf Distribution Implementation

The simulator uses Zipf distribution to model realistic user behavior:

// Zipf parameter: 1.07 (slightly skewed distribution)
zipf := rand.NewZipf(r, 1.07, 1, uint64(maxSubreddits))

// Popular subreddits get more users and content
subredditIndex := int(zipf.Uint64())

Benefits:

  • Realistic Modeling: Mimics real-world social platform dynamics
  • Popular Communities: Some subreddits naturally become more active
  • Long Tail Effect: Many smaller communities with less activity

πŸ”§ Actor System Design

Engine Actor

Responsibilities:

  • Process all user actions and state changes
  • Maintain data consistency across the system
  • Handle message routing and response generation

Key Methods:

func (e *Engine) Receive(context actor.Context)
func (e *Engine) registerUser(username string)
func (e *Engine) createSubreddit(name, creator string)
func (e *Engine) createPost(postID, subredditName, author, title, content string)
func (e *Engine) vote(postID, userID string, isUpvote bool)

Simulator Actor

Responsibilities:

  • Generate realistic user behavior patterns
  • Manage simulation lifecycle and timing
  • Coordinate with Engine for action execution

Key Methods:

func (s *Simulator) runSimulation(context actor.Context)
func (s *Simulator) simulateAction(context actor.Context)
func (s *Simulator) simulateCreatePost(context actor.Context)
func (s *Simulator) simulateVote(context actor.Context)

πŸ“ˆ Performance Benchmarks

Tested Configurations

Users Actions Subreddits Time Machine
100 500 10 0:05 M3 Pro
1,000 5,000 50 0:15 M3 Pro
10,000 25,000 100 0:45 M3 Pro
100,000 250,000 600 2:40 12-Core M3 Pro, 18GB RAM

Performance Characteristics

  • Linear Scaling: Performance scales predictably with user count
  • Memory Efficient: Optimized data structures for large simulations
  • Concurrent Processing: Full utilization of multi-core systems

πŸ“Š Simulation Output

User Actions Log

[REGISTER USER]  Registered as new user
[CREATE SUB]     Subreddit created: r/Sub 1 by User 1
[JOIN SUB]       User 2 joined subreddit r/Sub 1
[POST]           Post 1 created in r/Sub 1 by User 1: Post Title
[POST Comment]   User 2 commented on post Post 1: Comment content
[VOTE]           User 3 upvoted post Post 1
[Direct Message] DM sent to User 4: Hello there!
[SHOW FEED]      Feed for user User 2 -----

πŸ” Monitoring & Analytics

Real-time Metrics

  • Action Throughput: Actions processed per second
  • User Activity: Active vs. inactive user ratios
  • Content Distribution: Posts and comments per subreddit
  • Engagement Rates: Voting patterns and participation

Post-Simulation Analysis

  • User Karma Distribution: Reputation spread across users
  • Subreddit Popularity: Member counts and activity levels
  • Content Metrics: Post engagement and comment threading depth
  • Performance Stats: Execution time and resource usage

πŸ‘₯ Authors

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/actor-enhancement)
  3. Commit changes (git commit -m 'Add new actor feature')
  4. Push to branch (git push origin feature/actor-enhancement)
  5. Open a Pull Request

⚑ Built with Go's concurrency power and Proto Actor's distributed magic

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages