user-service

command module
v0.0.0-...-b99d2af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2024 License: MIT Imports: 8 Imported by: 0

README

user-service

Description

REST endpoints for user management:

  • POST /users - Create a new user.
  • GET /users/{id} - Retrieve user details by ID.
  • PUT /users/{id} - Update user information by ID.
  • DELETE /users/{id} - Delete a user by ID.
  • GET /users - List all users with pagination.

Repository: https://github.com/bmcszk/user-service

Setup instructions

Prerequisites
  • Docker
  • Docker Compose
  • Git
  • Goland v1.23 or higher
  • Make
  • (optional) Kubectl
Installation options
  • make compose - starts the docker compose environment
  • make test - runs tests using compose
  • make coverage - creates coverage report
  • make kind-up tilt-up - starts local Kind k8s cluster and Tilt deployment

Development

  • make sqlc - generates code using sqlc
  • make migrate-up - runs migrations up
  • make migrate-down - runs migrations down

Design decisions

  1. Simple project structure, directories:
  • sources:
    • db - database layer
    • api - api layer
    • logic - business logic layer
    • e2e - end-to-end tests
  • configs:
    • helm - helm charts
    • tilt - tilt configs
  1. Simplest http layer using standard library
  2. Database is Postgres
  3. Simplest db layer using standard library and SQLC for code generation.
  4. Migrations handled automatically using Golang Migrate
  5. Deployment can be managed by Helm
  6. Local dev environment can be managed by Tilt
  7. CI is done using Github Actions where Kind cluster is created and Tilt is deployed. Check: https://github.com/bmcszk/user-service/actions/runs/11915468146/job/33205800016

Assumptions

  1. User model is very basic but with possibility to add more fields through DB migrations
  2. No authentication, no authorization
  3. Many TODOs in code

Scalability Considerations

  1. Application can easily scaled using K8s manual and automatical scaling. Database can easily scaled using Cloud Native Postgres
  2. Designing the system to be able to handle 30k requests per minute with a latency of < 100ms. Step by step:
    1. Prepare configurable e2e test scenario running with up to 30k requests per minute.
    2. Prepare configuration and middlewares for telemetry, to monitor performance and latency of application and DB.
    3. Prepare test K8s cluster and deploy the application with DB.
    4. Run the e2e test scenario with small amount of requests per minute.
    5. Monitor the performance and latency of the application and DB.
    6. Gradually increase the number of requests per minute and monitor the performance and latency of the application and DB.
    7. Identify bottlenecks and adjust resources configuration, adjust number of instances of the application and DB.
    8. Go to step 5. until reaching the desired performance and latency.

Security

  1. Basic input validation introduced.
  2. DB queries are sanitized using prepared statements with params.
  3. Introducing SSL strongly recommended.
  4. Authentication and authorization can be implemented in Kubernetes using 3rd party solution like Kong or Nginx.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL