Skip to content
core-goPublic

About

No description or website provided.

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Repository files navigation

Health Check in Microservices

A lightweight, framework-independent health check framework for Go microservices.

Most health endpoints only answer one question:

"Is my HTTP server running?"

Production systems need a much more important answer:

  • Is the database reachable?
  • Is Kafka connected?
  • Is RabbitMQ available?
  • Is Elasticsearch healthy?
  • Is the external HTTP service responding?
  • Can this service actually perform its job?

core-go/health provides a simple, extensible, and production-ready way to monitor the health of your application's critical dependencies.

health


Why?

Many Go applications expose a health endpoint like this:

http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
    w.WriteHeader(http.StatusOK)
})

This only indicates that the HTTP server is alive.

Imagine a microservice that depends on:

  • Oracle
  • Kafka
  • Redis
  • Elasticsearch
  • External HTTP APIs

If Kafka becomes unavailable:

  • the HTTP server is still running
  • /health still returns 200 OK
  • Kubernetes considers the pod healthy
  • users begin experiencing failures
  • engineers spend valuable time finding the root cause

With core-go/health, the health endpoint immediately reports that Kafka is DOWN, allowing your monitoring platform to notify the correct team before users report problems.


Features

  • Lightweight
  • Framework independent
  • Production-ready
  • Kubernetes ready
  • Built-in providers for common infrastructure
  • Per-provider configurable timeout
  • Ready-to-use HTTP handlers
  • Pluggable provider architecture
  • Easy to extend with custom providers
  • Zero dependency on any web framework

Supported Providers

Built-in providers include:

Databases

  • SQL Database
  • PostgreSQL
  • MySQL
  • Oracle
  • SQL Server
  • MongoDB
  • Firestore

Search

  • Elasticsearch

Cache

  • Redis

Message Brokers

  • Kafka
  • RabbitMQ
  • IBM MQ
  • ActiveMQ
  • NATS

HTTP

  • HTTP Client

Custom

  • Custom Providers

Integration with Existing Systems

Designed to integrate seamlessly with existing Go libraries: Gorilla mux, Go-chi, Echo and Gin.

Framework Supported
net/http ✅
Gin ✅
Echo ✅

Samples:

net/http

http.Handle("/health", health.NewHandler(checker))

Gin

router.GET("/health", healthgin.NewHandler(checker))

Echo

e.GET("/health", healthecho.NewHandler(checker))

Using another framework?

Simply invoke the health checker and write the response using your preferred framework.


Configurable Timeout

A slow dependency should never block your health endpoint.

Since Kubernetes typically invokes health endpoints every few seconds, every provider supports its own timeout.

health.Add(
    kafka.NewChecker(
        producer,
        4*time.Second,
    ),
)

or

health.Add(
    http.NewChecker(
        "User Service",
        "https://user-service/health",
        4*time.Second,
    ),
)

Benefits:

  • Prevent hanging health requests
  • Detect slow or unreachable services
  • Keep Kubernetes probes responsive
  • Configure different timeout values for different providers

Example

checker := health.New()

checker.Add(sql.New(database))
checker.Add(redis.New(redisClient))
checker.Add(kafka.New(producer))
checker.Add(elasticsearch.New(client))
checker.Add(http.New(
    "User Service",
    "https://user-service/health",
))

http.Handle("/health", health.NewHandler(checker))

Example Response

Everything is healthy:

{
    "status": "UP",
    "services": [
        {
            "name": "database",
            "status": "UP"
        },
        {
            "name": "redis",
            "status": "UP"
        },
        {
            "name": "kafka",
            "status": "UP"
        }
    ]
}

Kafka is unavailable:

{
    "status": "DOWN",
    "services": [
        {
            "name": "database",
            "status": "UP"
        },
        {
            "name": "redis",
            "status": "UP"
        },
        {
            "name": "kafka",
            "status": "DOWN",
            "error": "connection refused"
        }
    ]
}

Architecture

                    +-----------------------+
                    |     Health Checker    |
                    +-----------------------+
                               |
        -----------------------------------------------------
        |         |         |         |         |            |
       SQL      Redis     Kafka    RabbitMQ   HTTP   Elasticsearch
        |         |         |         |         |            |
        -----------------------------------------------------
                               |
                        Health Response

Every provider implements the same interface.

Adding support for a new system only requires implementing a new provider.


Production Use Cases

Perfect for:

  • Kubernetes Readiness Probe
  • Kubernetes Liveness Probe
  • Docker Health Check
  • Amazon ECS
  • Google Cloud Run
  • Background Workers
  • Scheduled Jobs
  • REST APIs
  • Microservices

Why core-go/health?

Unlike a simple /health endpoint that only checks whether the HTTP server is running, core-go/health verifies the health of the infrastructure your application actually depends on.

This enables you to:

  • Detect dependency failures immediately
  • Reduce Mean Time To Detect (MTTD)
  • Improve production observability
  • Simplify troubleshooting
  • Standardize health checks across services
  • Reuse the same health framework throughout your organization

Real World Example

A typical microservice may depend on multiple infrastructure components.

Order Service
    │
    ├── Oracle
    ├── Kafka
    ├── Redis
    ├── Elasticsearch
    └── User Service (HTTP)

When Kafka becomes unavailable:

Without core-go/health

✓ HTTP Server

/health -> 200 OK

Everything appears healthy.

With core-go/health

✓ Oracle
✓ Redis
✗ Kafka
✓ Elasticsearch
✓ User Service

/health -> DOWN

Your monitoring system immediately identifies the failed dependency, allowing engineers to investigate the correct component instead of spending hours searching for the root cause.


Design Principles

  • Framework Independent — No dependency on Gin, Echo, or any other web framework.
  • Provider Based — Every dependency is implemented as an independent provider.
  • Extensible — Easily add custom providers.
  • Production Ready — Designed for Kubernetes and cloud-native applications.
  • Minimal API — Simple to learn and easy to integrate.

Philosophy

A healthy service is not simply one whose HTTP server is running.

A healthy service is one that can successfully communicate with all of its critical dependencies and continue serving requests.


Examples:

External Service Health Check Library

Cache Health Check Library

Database Health Check Libraries

Message Queue Health Check Libraries


License

MIT

About

No description or website provided.

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages