The Long Way for Creating a New Backend Server

Open SourceNode.jsAPI
Yuval hazaz
Yuval hazaz
Jul 27, 2022
The Long Way for Creating a New Backend ServerThe Long Way for Creating a New Backend Server

Creating a backend is a complex problem. At first, you’re happy that a new project is starting. But then, you check what’s required, and sooner or later, you get lost in the details. This doesn’t even depend on the type of project you’re building; monolith or microservices both entail challenges.

Days or weeks before you write the first line of business logic, you’ll have to choose a tech stack, set up logging and error handling, and create a deployment pipeline. And don’t forget all the boilerplate code you’ll have to write; in most cases, there’s much more value-added in the codebase than what is directly visible to your users.

Configuring your services and software correctly is an art in itself. Say you need a database or queue and spend days setting them up correctly. But did you remember to also set up migrations? That will bite you the first time you want to update your stack!

Nobody can afford to forget essential tasks when starting a new project. This article will take you through the vital steps to building a backend server.

Choosing the right stack

Selecting the right tools is a never-ending discussion in developer communities worldwide. Some people swear by building every project with the same programming language and framework. Others say it’s critical to use the most suitable tool for every project, even if it requires learning something entirely new.

The “right tool” will depend on you and your project. If you have a strict deadline for your project, you can’t wait a month for your team to get up to speed with a new technology, and more often than not, the language or framework you’re using might be good enough for the task at hand.

If your goal is to create something more efficient or responsive than an existing alternative, performing thorough research before jumping into the project with the tools you already know can pay off. Building with C or Rust might lead to slower project completion, but it could also give your project the performance edge needed to overtake your competition. After all, delivering something fast that nobody wants doesn’t help anyone.

So, make sure you know what you want to accomplish and what are your constraints before choosing a tech stack.

Writing boilerplate code

Depending on the tech stack you choose, you may have to write quite a bit of boilerplate code—especially when going for low-level technology to remove the last bit of latency.

This includes the setup for the API layer, folder structure, packages, naming convention, testing, connection for a formatter, and static code analysis. There is a lot of work that goes into writing code that fulfills your users' needs.

While you might be tempted to keep boilerplate code to a minimum, remember that while some of it might seem optional, these parts can still deliver indirect value to your project. For example, nobody likes to write repetitive testing code, but a month or a year after release, the person who has to implement the first big refactor will be happy to have all these tests to keep them safe.

Creating the database schema and data model

Modern systems often follow a modeling approach based on code that can be versioned—but you have to write this code as well.

A schemaless approach can be a quick alternative for prototyping. In a production project that you might be using for years, a well-defined data model and the database schema are essential to ensure everything keeps working as expected, even if the data structure changes over time.

Adding non-functional features

A user might not directly need authentication or authorization but features they do want often won’t work without these. How can you relate someone to their data if you don’t know who they are?

The same goes for logging. Your users don’t care about logging, but if things go wrong and your developers have to implement a fix, proper logging can save them a massive amount of time. And your users will appreciate issues being fixed as quickly as possible.

Again, it’s always tempting to cut corners; we all want to move fast and over-deliver. And sometimes, it might be okay to go with a simple authorization scheme that gets the job done instead of building a fully fledged, policy-based access control service.

Running and connecting to peripheral services

While not implemented by your in-house developers, databases, queues, and other services are still software you need to set up and connect to your backend.

Again, this will entail some kind of boilerplate, but you still need to make sure your backend can write data to somewhere. And you need to execute this step so that your team can run and connect to services on an ongoing basis.

This isn’t just about the code or configuration required to set things up; it can also include educating the people who have to write it.

Deploying the first version to the staging environment

When you finally move to your project’s deployment stage, you’ll face additional questions like those relating to your chosen tech stack.

Your stack may prescribe a specific deployment method. If your backend server is built with microservices, you’ll have to keep track of them, requiring additional tools. Docker and Kubernetes are tools that also require their share of work to get things up and running.

And if you go for infrastructure as code, there’s additional code you need to write. Terraform, CloudFormation, CDK, or Pulumi are excellent tools that keep your deployment well defined.

Plus, your backend needs to access other services and be accessible to your users and said services. You’ll need to set up environment variables for service credentials and ensure they aren’t leaked to malicious actors. Additionally, you’ll have to manage your network ports; otherwise, nobody will be able to connect to your new backend.

Leveraging the power of open-source

All the tasks above—boilerplate code, configuration, testing, logging, error handling, and deployment—can slow your project down. That’s why modern software is built with open-source tools. They allow you to move fast, and because professionals maintain them, you can still be sure everything is tested and properly maintained.

Amplication is an open-source tool that can help you build a fully functional backend in minutes. Backed by a team that has answered all of the questions above, Amplication lets you focus on delivering value right away. Less boilerplate, more business logic.

It’s not just a black box that gives you a backend in a few simple clicks. Amplication generates human-readable and editable TypeScript Node.js code for your server. You get numerous features, including a GraphQL API, REST API, authorization, authentication, admin UI, user management, logging utility, and error handling. All of this with the flexibility to customize it to your own code.

The generated code is built with proven open-source projects like NestJS, Prisma, PostgreSQL, Passport, GraphQL, Swagger, Jest, Docker, and many more.

So, if you’re planning to build a new backend, you might want to check out Amplication. Its code generators can increase your delivery speed tremendously. Because it uses open-source libraries and gives you direct access to the generated code, you’ll always remain in control. And if your requirements outgrow Amplication’s features later on, you can simply go on developing your backend like a regular software project.