Golang
Implement the Queue method
What does an empty interface in Go look like and what happens if you pass it as a function argument?
How exactly was the process of loading or building this data structured?
What happens to the program if a panic occurs in a separate goroutine?
// code snippet for the best() function // with error handling for no backend available
Imagine that the API you wrote with your team suddenly started responding five times slower. What would you start checking and how would you begin the investigation?
type Response interface{} type Backend interface { Invoke(ctx context.Context, req Request) (Response, error) } var _ Backend = &BackendImpl{} // addr contains the ip:port of a specific instance func NewBackend(addr string) *BackendImpl type backentry struct { backend Backend inflight int64 } type Balancer struct { backends []*backentry mu *sync.Mutex } var _ Backend = &Balancer{} // addrs contain the addresses of all balancable instances func NewBalancer(addrs []string) *Balancer { data := make([]*backentry,len(addrs)) for i,addr := range addrs{ data[i] = &backentry{ backend: NewBackend(addr), inflight: 0, } } return &Balancer{backends:data} } func(b *Balancer)Invoke(ctx context.Context, req Request) (Response, error){ b.mu.Lock() entry := b.best() atomic.AddInt64(&entry.inflight,1) b.mu.Unlock() defer atomic.AddInt64(&entry.inflight,-1) return entry.backend.Invoke(ctx,req) } func(b *Balancer) best() *backentry{ var best *backentry for _,entry := b.backends{ if best == nil || atomic.LoadInt64(&entry.inflight) < atomic.LoadInt64(&best.inflight){ best = entry } } return best }
What are the types of synchronous and asynchronous inter-service interactions, what tools are used for them, and what have you used in practice?
// code snippet for the best() function // with error handling for no backend available
Why are transactions needed in a database and what problems do they solve?
How do you enrich errors with context in Go and pass them further while preserving the original error?
How does sync.Map differ from map plus mutex?
What happens when a client cancels an HTTP request?
How active is your job search: how many interviews and companies are you communicating with?
What are the differences between gRPC and REST?
// code snippet for the best() function // with error handling for no backend available
// code snippet for the best() function // with error handling for no backend available
How does sync.Mutex differ from sync.RWMutex?
What happens to the entire program if a panic occurs in the HTTP handler?
Describe the process of analyzing and optimizing a long SQL query.