What is GOMAXPROCS? What happens if a very large number is set?
Golang
What are channels in Go? What types are there? How are they implemented under the hood?
// When updating an order, we need to send order data to multiple services (third-party APIs) // the number of services is growing (may be thousands+) // we wrote code, initially everything was fine, but over time our service started consuming a lot of memory func (s *orderService) SendOrder(ctx context.Context, hosts []string, order Order) { for i := 0; i < len(hosts); i++ { go func() { // Imagine this is a long network call response, err := s.httpClient.Send(ctx, hosts[i], order) if err != nil { s.logger.Error(ctx, "failed to send", err) return } s.logger.Info(ctx, "success", response) }() } }
What is a pessimistic lock?
What are the ways to concatenate strings in Go? What is the difference between + and strings.Builder?
What is a context in Go? How does context.WithTimeout differ from context.WithDeadline?
What will happen to Redis and clients if Redis is full and eviction policies are disabled?
How to ensure that all events for a single order go into one Kafka partition?
How was data caching implemented? What caching policy was used?
What is a Dead Letter Queue (DLQ)?
What is a slice? What is under the hood of a slice? How does the append function work?
// table goods: // ID | cnt_view // ----------- // 1 | 100 // 2 users started viewing the product with id = 1 simultaneously // and two parallel transactions were launched in our database // explain what the result will be? PostgreSQL func IncrementView(ctx context.Context, db *sql.DB, id int64) error { tx, err := db.BeginTx(ctx, nil) if err != nil { return err } defer tx.Rollback() var cnt int err = tx.QueryRowContext(ctx, "SELECT cnt_view FROM goods WHERE id = $1", id, ).Scan(&cnt) if err != nil { return err } cnt++ _, err = tx.ExecContext(ctx, "UPDATE goods SET cnt_view = $1 WHERE id = $2", cnt, id, ) if err != nil { return err } return tx.Commit() }
How was the figure of 25% calculated? Why not 20 or 30?
What is Mutex and RWMutex? How do they differ?
How does the garbage collector in Go work? When does it run? Can it be run manually?
func (r *OrderRepository) GetActiveOrderIDs(ctx context.Context, offset, limit int) ([]uint32, error) { var ( res []uint32 args []interface{} ) query := `SELECT id FROM "order" WHERE is_terminated = false LIMIT $1 OFFSET $2;` args = append(args, limit, offset) rows, err := r.slave.Query(ctx, query, args...) if err != nil { return nil, err } for rows.Next() { var orderID uint32 if err = rows.Scan(&orderID); err != nil { return nil, err } res = append(res, orderID) } return res, nil }
What are strings in Go? What do they represent under the hood?
What profiling tools are available in Go?
What is struct alignment in Go? How to optimize struct fields for memory?
Were there any nuances and difficulties in implementing Kafka? Was it your first experience?