📍 Cro | 💻 DevRel
If we have data, let's look at data. If all we have are opinions, let's go with mine.
Tiny version

Infrastructure from Code

If you're reading this, you're probably dealing with the same pain I used to feel when it came to setting up infrastructure on AWS. Those consoles are such a headache and they disobey all laws of UX. Luckily, there are other solutions out there that give you the ability to bypass the console, eg. Pulumi and other Infrastructure as Code providers. But those are detached from your code and increase the risk of human error, and I make a lot of human errors. Luckily, there's a third option and it's called Infrastructure from Code.

Instead of manually setting up and configuring servers and other infrastructure components, navigating through complex consoles or drowning in yaml files, you can simply add some annotations to the code and let the tools do the work for you. This means that you can define your infrastructure using code, and then use that code to automatically set up and configure everything that your app needs.

But why is this such a big deal? For starters, it can save you a ton of time and effort. Instead of spending hours or even days setting up your infrastructure, you can just write some code and let it do the work for you. This frees up your time to focus on the more important aspects of app development, like building and testing your app.

Another major benefit of Infrastructure from Code is that it allows for better collaboration among teams of developers. Since the infrastructure is defined using code, it can be easily shared and versioned using Git. This makes it easy for multiple developers to work on the infrastructure for an app at the same time, and ensures that everyone is working with the same version of the infrastructure.

And when it comes to deploying your app to different environments, Infrastructure from Code makes it a breeze. Since the infrastructure is defined using code, it can be easily modified and redeployed to different environments like development, staging, and production. This makes it easy to test and iterate on the infrastructure for your app, and ensures that your app is always running on the right infrastructure.

Example: Infrastructure from Code with shuttle

To give you an example, the code snippet below represents a 'Hello World' implementation written in Rust, using axum, a web application framework, and shuttle, a cloud development platform that let's you deploy your Rust code. This is barebones in a sense that it just creates a /hello route which is usually the stepping stone for any new project.

#[shuttle_service::main]
async fn axum() -> shuttle_service::ShuttleAxum {
    let router = Router::new().route("/hello", get(hello_world));
    let sync_wrapper = SyncWrapper::new(router);

    Ok(sync_wrapper)
}

Now, let's say that we are building a simple CRUD app. We would have to create a couple of POST/GET endpoints but more importantly, we would need a database to store data. With shuttle, and it's utiliziation of Infrastructure from Code, that's as simple as adding the #[shuttle_shared_db::Postgres] annotation.

#[shuttle_service::main]
async fn axum(#[shuttle_shared_db::Postgres] pool: PgPool) -> shuttle_service::ShuttleAxum {
    let router = Router::new().route("/hello", get(hello_world));
    let sync_wrapper = SyncWrapper::new(router);

    Ok(sync_wrapper)
}

And if we need to support secrets, we just add another annotation, in this example; #[shuttle_secrets::Secrets].

#[shuttle_service::main]
async fn axum(
    #[shuttle_shared_db::Postgres] pool: PgPool,
    #[shuttle_secrets::Secrets] secret_store: SecretStore,
) -> shuttle_service::ShuttleAxum {
    let router = Router::new().route("/hello", get(hello_world));
    let sync_wrapper = SyncWrapper::new(router);

    Ok(sync_wrapper)
}

Dead easy.

But it's not just about making things easier for developers. Infrastructure from Code also has some major benefits for the infrastructure itself. For example, since the infrastructure is defined using code, it's much easier to automate and manage. This can help to ensure that your infrastructure is always up to date, secure, and running smoothly. And with shuttle in this case, you are getting compile time insurance that you are getting exactly what you asked for.

Is it for you?

Of course, Infrastructure from Code isn't perfect. Troubleshooting issues can be challenging, as the underlying code and configuration may be complex and hard to debug and it may not provide as much flexibility as traditional methods for managing infrastructure so I'd definitely recommend to you to give it a go, get familiar with it and produce your own opinions on whether it's applicable for your projects, or not.

In the future, we can expect to see even more tools and technologies that make it easier for developers to manage the infrastructure for their apps using code. This will make it even easier for developers to focus on building and deploying their apps, rather than worrying about the underlying infrastructure.

So there you have it – the future of building apps with Infrastructure from Code is looking bright! It's a great way to save time, collaborate with other developers, and ensure that your app is running on the right infrastructure. Give it a try and see how it can benefit your development process!