Prev Next

Golang / GoLang System Architecture and Testing Interview Questions

What is chaos engineering and how do Go teams apply it to test microservice resilience?

Chaos engineering deliberately injects failures into a running system to discover weaknesses before they cause production outages. Go services are validated against: network failures, slow dependencies, pod restarts, and resource exhaustion.

// Chaos testing in Go: inject failures in tests

// Fault injection via interface
type FaultInjector struct {
    next     UserRepository
    failRate float64 // 0.0 to 1.0
    latency  time.Duration
}

func (f *FaultInjector) FindByID(ctx context.Context, id int) (*User, error) {
    // Inject artificial latency
    if f.latency > 0 {
        select {
        case <-time.After(f.latency):
        case <-ctx.Done(): return nil, ctx.Err()
        }
    }
    // Inject random failures
    if rand.Float64() < f.failRate {
        return nil, errors.New("injected fault: database unavailable")
    }
    return f.next.FindByID(ctx, id)
}

// Test service behaviour under 50% failure rate
func TestServiceUnderFaults(t *testing.T) {
    repo := &fakeUserRepo{users: testUsers}
    faulty := &FaultInjector{
        next:     repo,
        failRate: 0.5,
        latency:  100 * time.Millisecond,
    }
    svc := NewUserService(faulty)

    // Test that service handles partial failures gracefully
    successCount := 0
    for i := 0; i < 100; i++ {
        user, err := svc.GetUserWithFallback(context.Background(), 1)
        if err == nil && user != nil { successCount++ }
    }
    // With 50% fault rate and fallback, expect at least 90% success
    if float64(successCount) < 90 {
        t.Errorf("success rate %d%% too low with fallback", successCount)
    }
}

// Tools for chaos in production:
// - Chaos Monkey (Netflix) — terminates random pods
// - Litmus (CNCF) — k8s-native chaos experiments
// - Gremlin — cloud chaos-as-a-service
// - k6 + fault injection scenarios
What is the primary goal of chaos engineering?
Why is testing with a FaultInjector in unit tests valuable before doing production chaos experiments?

Invest now in Acorns!!! 🚀 Join Acorns and get your $5 bonus!

Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!

Earn passively and while sleeping

Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.

Invest now!!! Get Free equity stock (US, UK only)!

Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.

The Robinhood app makes it easy to trade stocks, crypto and more.


Webull! Receive free stock by signing up using the link: Webull signup.

More Related questions...

Compare REST/JSON with gRPC/Protocol Buffers. When would you choose gRPC for a Go microservice? How do you implement a gRPC server in Go, including error handling and interceptors? How do you build a production-ready gRPC client in Go with connection reuse and resilience? What microservice design patterns are most important to understand for Go interviews? How do you implement distributed tracing and observability in a Go microservice system? How do you implement event-driven communication between Go microservices using message queues? How do you manage database connections and sharding in a high-scale Go service? What caching strategies do you use in Go microservices and how do you prevent cache stampede? What are table-driven tests in Go and why are they the standard testing pattern? How do you write Go benchmarks and what does -benchmem tell you? How do you find and fix memory allocation hotspots in a Go service using profiling? How do you structure integration tests in Go that require real databases or external services? Explain the difference between mocks, stubs, and fakes in Go testing. When do you use each? How does Go's built-in fuzzing work and when should you use property-based testing? How do you test concurrent Go code correctly — including data races and timing issues? How do you decide where to draw service boundaries when decomposing a Go monolith into microservices? How do you version gRPC APIs in Go without breaking existing clients? How do you write unit and integration tests for gRPC services in Go? How do you load test a Go microservice and interpret the results? How does service discovery and client-side load balancing work in a Go microservice system? How do you design a consistent error model across multiple Go microservices? How do you implement the Saga pattern for distributed transactions in Go? What testing.T methods do experienced Go engineers use to write cleaner tests? How do you benchmark concurrent code with testing.B and what insights does it provide? How do you manage dependency injection at scale in a large Go service — wire, dig, or manual? How do you achieve zero-downtime deployments for a Go microservice in Kubernetes? How do generics in Go 1.18+ enable better system design and what are the trade-offs? How do you use test coverage meaningfully in Go — beyond just a percentage? What are the best practices for designing Protocol Buffer schemas in Go microservices? How do you implement safe retries in Go microservices? What are golden file tests in Go and when should you use them? How do you ensure data consistency across Go microservices without distributed transactions? What is the API Gateway pattern and how does it complement Go microservices? What memory leak patterns in Go are not goroutine leaks and how do you detect them? How do CQRS and event sourcing apply to Go microservice architecture? What is chaos engineering and how do Go teams apply it to test microservice resilience? What is contract testing and how does it apply to Go microservices? What makes a Go microservice horizontally scalable and what patterns break scaling? How do you implement configuration hot-reloading in a Go service without restart? How do you architect Go services for maximum testability at the package level? How do you implement feature flags and canary deployments in a Go microservice? How do you design a multi-tenant Go microservice? What is mutation testing and how does it evaluate test suite quality beyond coverage? How do you manage the full lifecycle of a Go microservice from startup to shutdown? How do you test Go code that processes streaming data or works with channels? Summarise the key principles for designing scalable Go microservices that senior engineers demonstrate.
Show more question and Answers...


Comments & Discussions