DEV Community

Lav Kush
Lav Kush

Posted on

GoFr: A Practical Introduction to Building Microservices with Go

Building microservices in Go can be lightweight and fast, but setting up the common pieces of a production-ready service can still take time.

This is where GoFr caught my attention.

GoFr is an open-source, opinionated microservice development framework for Go, designed to simplify the process of building and running microservices while providing features such as observability, configuration management, authentication middleware, gRPC, Pub/Sub, database migrations, health checks, WebSockets, and more.

🔗 GitHub: https://github.com/gofr-dev/gofr
🌐 Documentation: https://gofr.dev/docs

Why GoFr?

Go is already popular for backend and microservice development because of its simplicity, performance, concurrency model, and relatively small deployment footprint.

However, when building a real application, developers often need to configure several pieces around the core HTTP server:

  • Configuration management
  • Logging
  • Metrics
  • Tracing
  • Authentication
  • Database connectivity
  • Health checks
  • Messaging
  • HTTP clients
  • Background jobs
  • API documentation

GoFr aims to provide many of these capabilities through a common framework.

Instead of assembling everything from scratch, developers can work with a consistent framework and focus more on their application logic.

Getting Started

GoFr currently requires Go 1.24 or above.

After installing Go, a GoFr application can be started with:

go get -u gofr.dev/pkg/gofr
Enter fullscreen mode Exit fullscreen mode

A minimal application looks like this:

package main

import "gofr.dev/pkg/gofr"

func main() {
    app := gofr.New()

    app.GET("/greet", func(ctx *gofr.Context) (any, error) {
        return "Hello World!", nil
    })

    app.Run()
}
Enter fullscreen mode Exit fullscreen mode

Run the application:

go run main.go
Enter fullscreen mode Exit fullscreen mode

The service can then be accessed locally through the configured HTTP port.

The simplicity of the API is one of the interesting aspects of GoFr. A developer can start with a small service and gradually make use of the framework's additional capabilities as the application grows.

Features Worth Exploring

1. REST APIs

GoFr provides a straightforward way to define HTTP routes and handlers, making it easy to get a basic microservice running quickly.

2. Observability

For production services, knowing whether an application is healthy is just as important as building its functionality.

GoFr provides support for logs, metrics, and traces, helping developers understand what is happening inside their services.

3. Database Support

Microservices frequently need to interact with databases.

GoFr provides abstractions and health-check support for multiple data sources, allowing developers to work with database-backed services without building every integration layer themselves.

4. gRPC

For service-to-service communication, GoFr also provides gRPC support.

This can be particularly useful when building a collection of internal microservices that need efficient communication.

5. Pub/Sub

Event-driven architectures are increasingly common in distributed systems.

GoFr includes Pub/Sub support, which can be useful for applications where services communicate through events rather than only synchronous HTTP requests.

6. Authentication and Middleware

Authentication is another common requirement for backend services.

GoFr provides built-in authentication middleware along with support for custom middleware, allowing developers to extend the request-processing pipeline.

7. Health Checks

When multiple services are running together, health checks become important for monitoring and deployment systems.

GoFr provides health-check functionality for its supported data sources and services.

Why an Opinionated Framework?

GoFr describes itself as an opinionated framework.

That is an interesting design choice.

An unopinionated toolkit generally gives developers maximum flexibility but also leaves many architectural decisions to them.

An opinionated framework instead provides conventions and abstractions that encourage developers to structure applications in a particular way.

For teams, this can potentially make projects more consistent.

For beginners, it can also reduce the number of decisions required before getting a service running.

Open Source and Contribution

One thing I particularly like about open-source developer tools is that you don't have to remain only a user.

GoFr is open source, and developers can contribute through code, documentation, tutorials, reviews, and other forms of community participation.

The repository provides contribution guidelines covering areas such as:

  • Code formatting
  • Testing
  • Documentation
  • Pull requests
  • Code coverage
  • Development workflow

If you're interested in Go backend development, exploring an active open-source framework can also be a good way to understand how production-oriented projects are structured.

Who Should Explore GoFr?

GoFr may be worth exploring if you are:

  • Learning Go backend development
  • Building microservices
  • Working with Kubernetes-oriented applications
  • Interested in observability
  • Building APIs or distributed systems
  • Looking for an open-source project to contribute to
  • Interested in understanding how a production-oriented Go framework is structured

Final Thoughts

GoFr is an interesting project for developers who want to build microservices in Go while having a framework that brings several common backend requirements together.

Rather than treating it as just another HTTP framework, I think the more interesting part is its broader focus on microservice development, observability, integrations, and deployment-oriented capabilities.

If you're learning Go or working on backend systems, it's worth taking a look at the project and experimenting with a small service.

🔗 Explore GoFr on GitHub:
https://github.com/gofr-dev/gofr

📚 Read the documentation:
https://gofr.dev/docs

If you try GoFr, I'd be interested in hearing what you build with it and what you think could be improved.

Top comments (0)