Boot.dev Blog » Golang » Can Go Be Used in Web Development?

Can Go Be Used in Web Development?

By Natalie Schooner on October 6, 2023

Curated backend podcasts, videos and articles. All free.

Want to improve your backend development skills? Subscribe to get a copy of The Boot.dev Beat in your inbox each month. It's a newsletter packed with the best content for new backend devs.

Recently I saw an interesting post on Reddit: “I would like to be more full-stack,” user Fenugurod said. “I was studying Tailwindcsss and I’m pretty sure I can create really nice UIs with it. But what do you guys think about web development with Go? Most of my friends simply say to embrace the JS ecosystem with Nuxt or Next and use Go simply as an API.”

Here at Boot.dev, I’m biased. I love Go for nearly anything. It has so many great points – its concurrency, the goroutines, the compilation speed. But I also believe in using the right tool for the right job. The web development Go combo may be workable, but is it ideal?

The developers of Go certainly think so, seeing as they’ve published a whole blog post on the Web development Go combo. In their words, “Go delivers speed, security, and developer-friendly tools for Web Applications.”

Brief definitions: 🔗

When I say web development, I’m referring to the process of creating and maintaining websites and web applications that are accessible through the internet. It involves a combination of programming, design, and technical skills to build functional and visually appealing websites that cater to the needs of users.

Go, also informally known as Golang, is a statically typed, compiled language designed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. It’s beloved by programmers for its simplicity, efficiency, and strong support for concurrent programming.

Web Dev in Go? A short answer 🔗

All those things sound great for web development, right? So here’s my short answer: Web development with Go is not only possible but actually offers some advantages over the typical Python/JavaScript combo, for example. Go’s standard library provides a robust set of tools for building web servers and handling HTTP requests. Frameworks like Gin, Echo, and Buffalo have emerged to simplify the process even further, offering a range of features from routing to middleware support.

As I mentioned, Go is not the usual suspect. JavaScript and its vast number of frameworks (React, Vue, Angular, etc.) dominate this space. If you’re not ready to go full-Go, you can use Go in conjunction with JavaScript and its many framework children. For instance, you can build a Go backend that serves a React frontend, combining the strengths of both ecosystems.

There are also projects like WASM (WebAssembly) that allow Go to run in your browser, bridging the gap between Go and traditional front-end technologies. It’s worth mentioning that WASM, released for the first time in March 2017, is still in its early stages and might not be suitable for all projects.

In conclusion, if you want to become a full-stack developer with Go, it’s totally possible. Go can power your backend, and with the right tools and frameworks, you can also integrate it with popular front-end technologies.

If you’re in for the longer answer, let’s ride on down.

Background of Go 🔗

First, let’s go back a bit to understand the background of Go. Basically, its simplicity, efficiency, and robust standard library provide developers with the tools you need to build scalable and maintainable web applications, along with enough safety tools for the British Government to use it. (““In particular, Go’s concurrency model makes it absurdly easy to build performant I/O-bound applications.” – Gov.uk’s web developers).

Go, often referred to as Golang, was conceived in September 2007 by Robert Griesemer, Rob Pike, and Ken Thompson, all at Google, and was released to an eager public in November 2009. These men were shooting for a language without the unnecessary complexities of languages like C++ while maintaining their strengths. They wanted a system programming language that was modern, concise, and fast both in execution and compilation.

Go was designed with two core principles in mind: simplicity and productivity. Its syntax is clean, which makes it easy to read and write. This simplicity also reduces the room for errors, leading to more robust code. With features like a rich standard library and a straightforward approach to concurrency, Go makes developers more productive. The language’s design also reduces the need for extensive debugging, which as any developer will tell you, also increases productivity.

What makes Go so good? Five key features separate it from the pack:

  • Concurrency: Goroutines (lightweight threads managed by the Go runtime) and channels (a mechanism to safely communicate between goroutines) let developers write efficient, readable concurrent code.
  • Garbage Collection: An automatic garbage collector reclaims memory used by data structures that are no longer accessible.
  • Strong Typing: Go is a statically-typed language. The data type of a variable is checked at compile-time. This feature helps catch potential errors early in the development process.
  • Compilation Speed: Go is known for its fast compilation times. This rapid feedback loop allows for quicker iterations and testing.
  • Built-in HTML templating and HTTP routing in the stdlib: Go’s standard library comes with built-in packages for HTML templating (html/template) and HTTP routing (net/http). This makes it relatively straightforward to set up web servers and render dynamic content without relying on third-party libraries.

Go in Web Development 🔗

How does that all tie into web development? Let’s look over those features with an eye for Web development specifically.

Building web servers 🔗

One of Go’s strengths is its rich standard library, which I mentioned earlier. One package in particular is suitable for web dev: the net/http package. This package gives you a set of robust tools to quickly build HTTP servers. With just a few lines of code, you can set up servers, define routes, and handle requests. For simpler applications, you might not even need an external web framework.

Another strength is that concurrency I keep harping on about. Web servers often need to handle multiple requests simultaneously – for example, a user might be uploading a file while another is querying data, and yet another is logging in. In many traditional languages, handling these simultaneous tasks can be cumbersome, often requiring multi-threading or complex asynchronous programming models.

Go, however, was designed with this exact problem in mind. Its concurrency model is built around goroutines, which are much lighter than traditional threads and can be spawned in the thousands or even millions without significant overhead.

And then you can look beyond the vanilla packages for a golang framework or a third-party package that further simplifies web development or web application development:

  • Gin: Offers a martini-like API but with much better performance. It’s known for its speed and small memory footprint. Comes with middleware support, routing, and error handling. (This one was most commonly mentioned in the /golang subreddit)
  • Echo: Another high-performance, extensible framework. Echo focuses on performance and provides features like middleware support and data binding. Its API is designed to be simple and straightforward.
  • Buffalo: An ecosystem for rapidly developing web applications in Go. It aims to be a one-stop-shop for Go web development.
  • Gorilla Mux: While not a full-fledged framework, Gorilla Mux is a powerful URL router and dispatcher. It’s a part of the Gorilla web toolkit, which provides a range of tools and libraries for building web applications.

These Golang web frameworks are functional and simple.

What about the other possibilities? 🔗

There are so many great programming language alternatives that can be used for web development. How does Go stack up against Python and JavaScript (Node.js specifically)?

Go is a statically-typed, compiled programming language, which generally means superior performance in terms of raw execution speed compared to interpreted languages like Python. Its concurrency further boosts its performance in scenarios like web servers where handling multiple simultaneous connections is crucial.

Python wins the award for beginners at the “hello world” stage. It is beloved for its simplicity and readability. But it is often slower than Go, especially in CPU-bound tasks. However, with frameworks like Django and FastAPI, Python remains a popular choice for web development, especially for applications where development speed is more critical than raw performance.

JavaScript, when run on the server-side using platforms like Node.js, offers event-driven, non-blocking I/O, making it suitable for I/O-bound tasks. Individual tasks might run slower than in Go, but Node.js can handle many tasks concurrently thanks to its event-driven architecture. But I would argue that Go’s goroutines often provide a more straightforward approach to concurrency than Node.js’s callback model.

Pros of Doing Golang Web Development 🔗

Let’s break down the pros. The main pros? Speed, concurrency, and built-in HTML templating. I won’t spend too long since we’ve covered these above, bar the HTML section.

  • Speed: Go’s speed and efficiency contribute to faster development cycles and high-performance web applications.
  • Concurrency: Go’s concurrency model benefits web development, especially for handling multiple requests simultaneously

Go’s built in HTML templating, speed, and HTTP routing makes it a perfect match if you’re interested in new web development tools like HTMX. Plus, Go’s standard library includes the html/template package, which lets you easily render dynamic HTML content without needing any third-party libraries. It also automatically handles common security issues like cross-site scripting (XSS) by safely escaping strings by default.

It’s also worth highlighting that, no surprise, Go plays well with the Google suite of products and services, which are prevalent in the development space. For instance, the App Engine is a fully managed platform on Google Cloud that allows you to deploy applications without managing the underlying infrastructure. The standard environment is optimized for applications with fluctuating traffic. It has built-in support for Go. You can write your Go web application, define your web app’s configuration in an app.yaml file, and deploy it directly to App Engine. Automatic scaling, versioning, and zero server management for your web application, all effortless.

There’s one final reason it makes sense to use a backend language like Go for full-stack web development: an overall simpler ecosystem. I loved how Reddit user Markuswustenberg put it in their answer to Fenugurod’s question above:

“I’ve really embraced writing classic server-side-rendered UIs again. The simplicity is refreshing, and especially on smaller projects, where there’s no dedicated backend and frontend team, it’s nice to be able to just work on one codebase (in Go) and not write all the API glue code, handle network error cases, etc. Also, there’s no context switch, and you don’t have to keep up with the whole JS ecosystem, which I think is nice.”

In short, Go is great for server-side rendering in small projects due to its simplicity. It offers a unified codebase, reducing complexities and stops you from having to keep up with what can sometimes feel like JavaScript’s Framework Of The Week.

Cons of Go for Web Dev 🔗

Now let’s cover a few of the most common obstacles in Go for web development.

Some folks might say that Go is tough to pick up. This might be true for novices, or for folks who are new to static typing because they’ve come from Python, which uses dynamic typing. But it’s an incredibly simple language. Personally, I’ll add that even if you’re new to it, the documentation is clear and easy to comprehend, and the community of Gophers is always happy to lend a helping hand to a newbie.

It is worth highlighting that Go has a smaller ecosystem compared to JavaScript and Python. These languages have been around for longer and have a vast array of libraries, frameworks, and tools tailored for web development. For almost any feature or functionality you can think of, there’s probably a library or tool in JavaScript or Python that can help. It’s especially low on UI-specific libraries compared to JavaScript. There’s also no “official” Golang IDE, though there are several IDEs and editors that support Go development.

And finally, there are limitations of using Go for developing user interfaces in web applications. Go is designed for server-side tasks, not front-end development. And while Go’s use with WebAssembly helps mitigate some of that, it’s still maturing and lacks the robustness of traditional JavaScript frameworks.

It’s your choice 🔗

In sum, Go is a great pick for you if you’re a web developer, at least in my eyes. It’s fast, it’s efficient, it’s concurrent, and it has a lot of useful, built-in functionality. If you’re a Golang developer already, it’s totally feasible to use it for full-stack development. And if not, there are still enough benefits to using Go for web development that it might be worth a try regardless.

The only time I would recommend not using Go for web development would be if you’re working on a project that heavily relies on the vast ecosystem of a specific language or framework, or if your team is deeply entrenched in another language and the switch would be too disruptive. Ultimately, the best tool depends on the project’s needs and the team’s expertise.

Otherwise? You’ve got nothing to lose from learning how to do web development with Go. Have fun!

Find a problem with this article?

Report an issue on GitHub