Skip to content

iangfernandes96/twitter_clone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twitter Clone API

A Rust-based Twitter clone API using Actix-web and ScyllaDB, designed to demonstrate high-performance social media backend capabilities.

Features

  • User Management (create users)
  • Tweet Operations (create, fetch)
  • Timeline Management (user timeline, home feed)
  • Three-node ScyllaDB cluster for high availability
  • Data seeding capabilities
  • Load testing suite
  • Grafana + Prometheus Monitoring

Prerequisites

  • Rust (latest stable version)
  • Docker and Docker Compose
  • k6 (for load testing)

Getting Started

1. Setting up the Database

The project uses a three-node ScyllaDB cluster. Start it using Docker Compose:

docker-compose up -d --build

Wait for all nodes to be ready (usually takes 1-2 minutes). Verify the cluster status:

docker exec -it scylla-node1 nodetool status

2. Creating the Schema

Connect to ScyllaDB and create the schema:

docker exec -it scylla-node1 cqlsh

Then paste the CQL commands in db_init.sh

3. Running the Application

Build and run the application:

cargo build --bin twitter_clone
cargo run --bin twitter_clone

The API will be available at http://localhost:8080

4. Seeding Test Data

To populate the database with test data:

cargo run --bin seed

This will create:

  • 100 random users
  • 20 tweets per user
  • Appropriate timeline entries

5. Load Testing

Install k6:

brew install k6

6. Monitoring

After running

docker-compose up --build

Navigate to http://localhost:3000

API Endpoints

Users

  • POST /api/users - Create a new user
    curl -X POST http://localhost:8080/api/users \
      -H "Content-Type: application/json" \
      -d '{"username": "testuser", "email": "[email protected]", "password": "password123"}'

Tweets

  • POST /api/tweets - Create a new tweet

    curl -X POST "http://localhost:8080/api/tweets?user_id=USER_ID" \
      -H "Content-Type: application/json" \
      -d '{"content": "Hello, World!"}'
  • GET /api/users/{user_id}/tweets - Get user's tweets

    curl "http://localhost:8080/api/users/USER_ID/tweets"

Feed

  • GET /api/feed - Get user's home feed
    curl "http://localhost:8080/api/feed?user_id=USER_ID"

Development

Useful Commands

Check ScyllaDB logs:

docker-compose logs -f scylla-node1

Connect to specific node:

docker exec -it scylla-node1 cqlsh

View cluster status:

docker exec -it scylla-node1 nodetool status

docker-compose up --build

Seeding data

cargo run --bin seed

Running server

cargo run --bin twitter_clone

Running Load test

On macOS

brew install k6

k6 run --out json=test_results.json load_test.js

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published