Skip to content

lacey1998/RestfulAPI-Go

Repository files navigation

Distributed Systems

Overview

This assignment introduces Go, RESTful APIs, cloud deployment, and basic performance testing.
I implemented a simple backend service using the Gin Web Framework, deployed it to AWS EC2, and evaluated its performance under load.


Part I: Go + Gin REST API

  • Implemented a RESTful API with endpoints:
    • GET /albums → returns all albums as JSON
    • POST /albums → adds a new album from JSON request body
    • GET /albums/:id → returns a specific album by ID
  • Learned about:
    • go mod init and dependency management with go get
    • Handlers, endpoints, and JSON serialization
    • Difference between localhost and 0.0.0.0

Part II: Deployment to AWS EC2

  • Created and configured an EC2 instance (Amazon Linux 2023, t2.micro)
  • Steps:
    1. Generated SSH key pair (rsa_pem.pem)
    2. Connected via SSH:
      ssh -i rsa_pem.pem ec2-user@<EC2_PUBLIC_IP>
    3. Cross-compiled Go program for Linux:
      GOOS=linux GOARCH=amd64 go build -o server main.go
    4. Uploaded binary with scp and ran on EC2
  • Configured Security Group to open port 8080
  • Verified deployment with:
    curl http://<EC2_PUBLIC_IP>:8080/albums

Part III: Performance Testing

  • Wrote a Python script (load_test.py) to: Send continuous GET requests for 30s Collect response times Visualize results (histogram + scatter plot) Compute statistics (average, median, percentiles)
  • Results: Average latency: ~65 ms Stable baseline, with a few slow outliers (>100 ms) Demonstrated long tail latency
  • Insights: t2.micro has limited CPU → variability under load Tail latency grows worse with higher concurrency Network + server both contribute to delays

Demo Instructions

  1. Start EC2 instance
  2. SSH into instance:
    ssh -i rsa_pem.pem ec2-user@<EC2_PUBLIC_IP>
  3. Run server:
    ./server
  4. Test SPI:
    curl http://<EC2_PUBLIC_IP>:8080/albums

Repository Contents

  • main.go → Gin REST API code
  • go.mod, go.sum → Go module files
  • load_test.py → Python load testing script
  • README.md → this file

About

RESTful API built with Go and Gin, deployed on both GCP and AWS EC2, with performance testing and latency analysis using Python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors