A fully functional Reddit-style clone built in Go, featuring a high-performance server and a command-line client.
This project demonstrates modern backend design patterns, concurrency handling, and a modular API system — all without external databases.
- 🔐 User System: Register, join/leave subreddits, track karma
- 🌐 Subreddits: Create, subscribe, and manage communities
- 📝 Posts & Comments: Threaded discussions with upvotes/downvotes
- 💬 Direct Messaging: Send and reply to DMs with threads
- 📰 Personalized Feed: Ranked feed based on subreddit subscriptions
- 📊 Metrics: Real-time server performance stats (posts, comments, memory, requests/sec)
- ⚡ Concurrency & Rate Limiting: Built using Go’s sync primitives and token-bucket rate limiter
- 🖥️ Simulation Mode: Generate activity with multiple simulated clients
- Language: Go 1.21+
- Server: Go HTTP server with actor-style state management
- Client: CLI tool with colored output
- Libraries:
logrusfor structured loggingfatih/colorfor CLI output stylinggolang.org/x/time/ratefor rate limiting
redditclone/
├── client.go # CLI client (separate binary)
├── main.go # Server (separate binary)
├── go.mod # Go module
├── config.json # Optional — server config (falls back to defaults if missing)
├── subscriptions.json # Created by client — local subscription cache
├── Readme.md # This file
└── REPO_DEEP_DIVE.md # Technical deep dive for engineers
-
Clone the repository
git clone https://github.com/yourusername/redditclone.git cd redditclone -
Install dependencies
go mod tidy
-
Run the server
go run main.go
- Default port: 8080
- Optional
config.jsonin project root (port, rate limit, log level, etc.) - Graceful shutdown on SIGINT/SIGTERM; writes
final_metrics.jsonon exit
-
Run the client
go run client.go -action=help
- Server must be running at
http://localhost:8080
- Server must be running at
Build binaries:
go build -o server main.go
go build -o client client.go| Action | Command |
|---|---|
| Register user | go run client.go -action=register -username=alice |
| Create subreddit | go run client.go -action=create_sub -subname=golang |
| Join subreddit | go run client.go -action=join_sub -username=alice -subname=golang |
| Leave subreddit | go run client.go -action=leave_sub -username=alice -subname=golang |
| Create post | go run client.go -action=post -username=alice -subname=golang -title="Hello Go" -content="Excited!" |
| Comment | go run client.go -action=comment -username=alice -post_id=1 -content="Nice post!" |
| Vote (upvote/downvote) | go run client.go -action=vote -voter=alice -target_type=post -target_id=1 -vote_type=upvote |
| Get karma | go run client.go -action=get_karma -username=alice |
| View feed | go run client.go -action=feed -username=alice |
| Send DM | go run client.go -action=dm -from=alice -to=bob -content="Hi!" |
| Reply to DM | go run client.go -action=reply_dm -from=bob -to=alice -content="Hello!" -original_dm_id=1 |
| List DMs | go run client.go -action=list_dm -username=alice |
| Server metrics | go run client.go -action=metrics |
| Simulate load | go run client.go -action=simulate -simulate_clients=5 -actions_per_client=10 |
Optional config.json in the project root:
{
"port": 8080,
"rate_limit": 100.0,
"rate_burst": 200,
"log_level": "info",
"metrics_update_interval": "10s",
"request_timeout": "5s",
"shutdown_grace_period": "10s"
}Server flag: -config=config.json (config path).
HTTP endpoint:
curl http://localhost:8080/metricsExample fields: total posts, comments, DMs, subreddits; active users; subreddit stats; karma distribution; requests/sec; memory usage; avg/max response times; rate limit exceeded count.
On graceful shutdown, metrics are also written to final_metrics.json.
This project is licensed under the MIT License. Feel free to use, modify, and distribute.