Backend development for frontend developers

The post I wish I had when I was learning backend development.

If you’re a frontend developer, backend development can sound intimidating. It’s home to some of the most exotic phrases in development: PostgreSQL, RESTful APIs, Kafka, and Nginx, and on the infrastructure side, Kubernetes clusters, load balancers, the AWS/GCP/Azure ecosystem, and Redis – which sounds similar to Reddit but it’s actually

an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes.

Any sane person would feel overwhelmed. I did, too, and searched for a good post to explain the philosophy behind backend development, but I couldn’t find one. That’s why I’m writing this. This post will show you

  1. the main purpose of backend development
  2. what, exactly, backend development allows you to do
  3. two concepts that caused “eureka!” moments in my understanding
  4. how to select a backend framework to start with
  5. and how can you teach yourself backend development

The purpose of backend development

Backend development is all about storing and retrieving data. That’s it. Read that sentence again, because that’s all you’re trying to do.

A lot of your work will revolve around accessing data from a database, which you can think of like a big text file. Databases can sound intimidating if you’ve never worked with them, but they’re built to be easy to use.

For instance, in Ruby on Rails, I can create a list of all the users in my database like this:

foo = User.all

You can loop through foo like you would an array. Simple, right?

What can you do with backend development?

Once a user closes your website, your frontend code stops running. Your event listeners disappear, your interval timers stop, and so on.

But what if you want to email your users, or text them, or send a push notification when something happens on your site? Then you need to program a “robot” that can handle it for you.

That’s where backend development comes in. Backend development lets you control a server – another computer. With backend development, you can make this computer do whatever you want, whenever you want – even if the user isn’t currently on your site. Backend development allows you to charge their credit card, send messages to a Slack channel, or crawl Reddit every night at 1 AM to calculate the subscriber growth on your favorite subreddits.

Most of our websites wouldn’t work without backends. We need this infrastructure in place so we can log into our applications, send our reset password emails, get notified when people reply to us, and so on.

Now, let’s talk about the two key parts of backend development.

Backend development concepts

Understanding the following two concepts gave me my biggest breakthroughs in backend development:

The roundtrip

Have you ever wondered how the Internet works? Let’s break it down with some plain-English-style code. The scenario is: a person visits your posts index on your blog. Here’s what happens:

Your backend handles the routing:

When someone arrives at '/posts'
  run the function 'getPosts'

You run the getPosts function, which grabs the posts from the database:

function getPosts {
  retrieve posts from database
}

And then the backend generates HTML from our ‘/posts’ template:

<ul>
  { for each post }
    <li>{ post }</li>
  { end }
</ul>

Then it sends the finished HTML to the user.

<ul>
  <li>Backend development for frontend developers</li>
  <li>My mechanical keyboard review</li>
  <li>What I learned from General Iroh</li>
</ul>

This is what’s happening on most of the websites that you visit every day. Basically, backends retrieve data, assemble it, and send it down to the user.

Now let’s talk about how we add data to the database.

Request methods

Sometimes we want to read a blog post, but other times, we want to post a new one. Your browser helps you accomplish both of these tasks by using request methods. These are some of the most common ones:

  • GET retrieves a blog post so you can read it.
  • POST creates a new blog post with the data you send.
  • PUT updates a blog post with the data you send.
  • DELETE deletes a blog post.

Whether you knew it or not, you’ve already used POST on the frontend because of the <form> tag. When you submit a form, it submits a POST request to the server. And we often use frontend development tools like JavaScript’s fetch(), axios, or jQuery to make all of these types of requests as well. Backend development is just opening the door to handle this data. Here’s another plain-English example:

Handle a POST request:

When someone makes a POST request to 'example.com/new-post',
(which they would do by submitting a form), run createPost

Create the post, and redirect the user to the post index:

function createPost {
  create the new post
  redirect the user to example.com/posts
}

A lot of your work in backend development will revolve around consuming requests. You’ll want to make sure that users can perform a GET request to read a blog post, a POST request to publish a new one, and so on.

These concepts control everything around us. When you order something on Amazon, you submit your payment form with a POST request, it adds a field to their Orders database, and then their warehouse GETs that data and ships your package to you.

What backend framework should I use?

For context, I was a React engineer before I made the transition to backend development. I was also self-taught, if that matters to you.

I wrote a long post about my search for a backend development framework in my post Node vs. Firebase vs. Laravel vs. Rails. I ended up choosing Ruby on Rails because (after the first several weeks of acclimation) it was extremely easy to build with. Ruby on Rails enables me to spin up an entire application in a weekend, which means I can create products faster (I like to make and sell things). I also love the beauty of its underlying language, Ruby – it’s like poetry.

Even though I was a React engineer, I shied away from JavaScript frameworks because they required a little too much assembly. Rails was very much “batteries included,” which I preferred as a beginner. Now that I know Rails, I feel that I’d have a much easier time learning a different framework.

Still, I recommend that you try several and make your own choice. Choose something that’s easy to learn, because you can always extrapolate that skillset to learn others later. Choosing any backend framework is a step in the right direction.

How can I teach myself backend development?

Everyone learns in different ways. Reading books feels like a slog to me, so my favorite way to learn is by building things – I’ll choose something simple (like a blog) and try to build it. For instance, this is what I did to learn Ruby on Rails:

  1. To practice, I decided I would build a simple blog. It would have a homepage that listed all the posts, and you could click on a post to read it. Blog posts would have titles and bodies – nothing else.
  2. I found and followed a short YouTube video on how to build a blog with Rails.
  3. Then, I tried to do it again without following the video.
  4. I decided I wanted to add user accounts. I searched for a blog post on how to add user accounts to Rails, and I followed it.
  5. Then, I tried to create a blog with user accounts from scratch.
  6. Once that was done, I decided that I wanted to learn a little more, but “I didn’t know what I didn’t know.” I found a popular Rails book (the Hartl one) and skimmed the first few chapters until I got bored.
  7. I kept building things that sounded fun, until eventually, I got good at Rails.

I didn’t do this in one sitting – it happened over the course of a few days.

I like to think of this as “previewing” a language. Worst case scenario, I spend a few days learning a language that I won’t use – but I still learn new things in the process. Best case scenario, I learn something that I love to use, and it helps me build awesome things. It’s a lopsided bet.

Conclusion

If you’re a frontend developer, backend development can seem intimidating. But at the end of the day, it’s just about retrieving data to display on the frontend – or opening the door to add <form> data to the database.

If you choose a backend framework that’s easy to learn, you can always extrapolate your skillset to learn others. Do some experimentation – you’ll find that the backend is much less scary to work with than you think.