Building a production-ready REST microservice in Rust

Posted 2023-05-07 09:00:00 by sanyi ‐ 2 min read

This will be a series of articles, showing a way to build a production-ready REST microservice in Rust

There are similar articles, books on this topic already available on the net, most notably Zero to Production in Rust.

I do not want to replicate them, just show my views on this topic, test some ideas.

I will not reinvent the wheel but build on the wide range of already available Rust libraries like the family.

I plan to use asynchronous programming wherever possible.

You will be able to follow the development of the codebase on GitHub. The code will be open source, covered by the permissive MIT license.

There will be articles not just about the Rust codebase but related topics too: adding a database, a log server and a telemetry collector to the project, handle caching, experiment with the CQRS and Event Sourcing patterns, message queue implementations, etc. I plan to use docker to run the related services and provide complete docker-compose configurations so you will be able to pull up a test environment easily.

I love dogs so the theme of this imaginary microservice will be around the database of a dog shelter: storing information about the dogs, make the database searchable for potential adopters.

Subjects I plan to address:

  • application startup
    • processing of command line parameters
    • processing of environment variables, .env files
    • loading and dynamic reloading of application configuration
    • planning for different application environments (like dev, staging, prod)
    • structure for multiple CLI commands, subcommands
  • web application server
    • starting an async webserver, probably warp or axum
    • adding routes, building a structure for handlers
    • adding a database, probably PostgreSQL, but strive for a database-independent architecture
    • building a minimal domain model to start with, implement persistency
    • handling the issue of database migrations
    • building the API, adding OpenAPI based documentation and Swagger UI
    • adding middlewares like authentication, authorization
  • observability and testing
    • adding telemetry, logging, tracing to the project
    • building automated test scenarios for the API
    • generating test data and filling up the database for realistic load tests
    • load testing the application, analyze the results
  • introduce the CQRS and Event Sourcing patterns
    • demonstrate the importance of the above patterns for caching, scalability
    • adding message queues and asyncronous background processing

I assume these topics will provide enough work for a couple of months.

Next article ยป

rust microservice dog-shelter