Skip to content

Commit

Permalink
build: add blog post content as to why go is ideal for webservices
Browse files Browse the repository at this point in the history
Signed-off-by: soypete <[email protected]>
  • Loading branch information
Soypete committed Jan 12, 2025
1 parent 76a9850 commit 8bcaf22
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Golang Webservices in 3 weeks

This repo contains the examples and exercises for The O'reilly online learning course[Go Web Development in 3 weeks](https://www.oreilly.com/live-events/go-for-web-development-in-3-weeks/0636920091015/).

* [![wakatime](https://wakatime.com/badge/user/953eeb5a-d347-44af-9d8b-a5b8a918cecf/project/815add1c-01f3-412e-b6cd-730805338e0e.svg)](https://wakatime.com/badge/user/953eeb5a-d347-44af-9d8b-a5b8a918cecf/project/815add1c-01f3-412e-b6cd-730805338e0e)

---

## Course Description

In this course, you will learn all the steps to build a web service in [Go](https://go.dev/). From starting the service to monitoring your service, it is meant to give you a comprehensive guide for building production-level service. The first section of the course will handle building restful best practices in Go. Communication is key for designing and building your services and is the foundation on which your functionality will be built. The second section is all about databases. Each web service needs a layer to store, fetch, and manipulate the data communicated with it. We need to make sure our data foundations are strong so we maintain the state of our services. The last section is an overview of reliability. This section just goes over reliability basics, but they are vital things that every engineer should include when building a web service. This course does not go over [Go](https://go.dev/) basics.

## pre-requisites
Expand All @@ -23,23 +23,25 @@ If you are new to go, work through these exercises first

---

# Day 1 - Rest API protocols
## Course Outline

### part 1 - Rest API protocols

* [Exercise 1](restful-go/README.md): std lib listenAndServe
* [Quiz](http-quiz/): Status Codes
* [Exercise 2](restful-go/README.md): Using a web framework
* [Exercise 3](restful-go/README.md): Client to query hosted server
* [Exercise 4](restful-go/README/md): HttpTests

# Day 2 - Databases for webservices
### Part 2 - Databases for webservices

* [Exercise 1](database/README.md): Connect to a live database
* [live coding](database/demo/): [SQLC](https://sqlc.dev/) and [goose](https://github.com/pressly/goose)
* [Exercise 2](database/README.md): Add client and interface
* [Exercise 3](database/README.md): Unit tests with mock client
* [SQL quiz](sql-quiz)

# Day 3 - Metrics and Monitoring
### Part 3 - Metrics and Monitoring

* [Exercise 1](reliable-webservice-go/README.md): API Auth
* [Exercise 2](reliable-webservice-go/README.md): Middleware
Expand Down
60 changes: 60 additions & 0 deletions docs/whygo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Why Go is the Best Modern Programming Language for Web Services

---

## What is a Web Service?

Web Service is an overloaded term in the current software ecosystem. I am ok with that, but for argument sake let me explain why I think a webservice is more that just something that connects to a website.

A web service, as my colleague [Tod Hansmann]() aptly defines, is "any piece of software that makes and receives communication over a network protocol." This broad definition captures a variety of applications. Some of them we call backend services, some we call [CRUD]() services, and others we use just for serving data onto websites. To me the use case doesn't matter all that much. If you are build a piece of software from the ground up intented to handle request you are building a webservice. Whether you're handling HTTP requests, gRPC communication, or WebSocket connections, that software is a web service and needs to be built with the right tools.

Go, in my humble opinion, is the best modern programming language, period. I basically use go as my swiss army knife for all my programming needs, but when I am evaluating languages and tools for production grade, scalable, and reliable web services, even with my bias, Go is the best choice. Why is that? It starts with the language itself.

### The Power of Go’s Standard Library

Go's standard library is a treasure trove for web service development. Unlike many languages that require third-party libraries in order to effectively build endpoints and make efficient network requests (yes I am looking at Rust and Python), Go provides built-in, high-performance tools to handle critical tasks. For instance:

- The **`net` package** simplifies network communication.
- The **`database/sql` package** streamlines database interactions.
- Built-in **testing tools** support reproducibility, making it easier to write, run, and maintain reliable code.

This comprehensive standard library means you can start building robust web services without searching for or vetting dependencies. If you have ever had to deal with dependency hell, you know how valuable this is. If you have ever had to worry about compliance and security, you know how valuable this is. If you have ever had to worry licensing and support, you know how valuable this is.

### Versatility Across Protocols

Go excels in supporting modern web service protocols. Whether you're working with HTTP, gRPC, WebSockets, or GraphQL, Go’s ecosystem delivers. Its native support for RESTful APIs is particularly noteworthy, with excellent built-in support for handling JSON and first class libraries for protobuf serialization. Whether you're building public-facing APIs or internal microservices, Go offers scalability and ease of use for both backend and frontend needs.

### Secure by Design

Many webservice developers get caught in their frameworks like Srping or Django, and forget about the security of their services. This is a fundamental part of building any kind of software and Go has you covered.

Security is non-negotiable for web services, and Go delivers here as well. Their fuzzing test suite is a prime example of how Go prioritizes security and reliability. This allows you to create unpredictable inputs to your code, ensuring it can handle unexpected data gracefully and to prevent security vulnerabilities.

It is also easy to built authentication and authorization mechanisms, ensuring your services are secure by design from anything like oauth2 to SAML.

### Readable, Scalable, and Maintainable

Go’s simplicity is intentional and by design. Its syntax is clean and minimalistic, making it easy to learn for newcomers and straightforward to debug for seasoned developers. This readability translates directly to scalability in organizations, as teams can onboard quickly and collaborate effectively.

Since Go is a compiled language, runtime errors are minimized, and CI/CD pipelines can focus on meaningful unit and integration testing. This leads to faster deployments and a smoother development lifecycle.

Moreover, Go was created with cloud-native development in mind. Its lightweight binaries and cross-platform support mean your web services can run on any major operating system and thrive in containerized environments like Docker and Kubernetes.

### Learn to Build Web Services with Go

I while ago, I gave several 3 way workshops on Go for WebServices. I have turned them into a series of Youtube videos. You can watch them here:

- [Go for Web Services: Part 1](https://www.youtube.com/watch?v=V9SvDd3e1eM)
- [Go for Web Services: Part 2](https://www.youtube.com/watch?v=V9SvDd3e1eM)
- [Go for Web Services: Part 3](https://www.youtube.com/watch?v=V9SvDd3e1eM)


for Exercices please check out this [repo](https://github.com/Soypete/WebServices-in-3-weeks)

---

## Conclusion

Go is the best modern programming language for web services. Its standard library, protocol support, security features, readability, scalability, and maintainability make it the ideal choice for building robust, reliable, and secure web services. Whether you're building RESTful APIs, gRPC services, or WebSocket connections, Go has you covered. If you're new to Go, I encourage you to explore its capabilities and see for yourself why it's the best choice for web service development.


0 comments on commit 8bcaf22

Please sign in to comment.