Sobes.tech

What is GOMAXPROCS? What happens if a very large number is set?

199

What are channels in Go? What types are there? How are they implemented under the hood?

194

// 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) }() } }

Middle+
194

What are the ways to concatenate strings in Go? What is the difference between + and strings.Builder?

191

What is a context in Go? How does context.WithTimeout differ from context.WithDeadline?

191

What will happen to Redis and clients if Redis is full and eviction policies are disabled?

189

How to ensure that all events for a single order go into one Kafka partition?

189

How was data caching implemented? What caching policy was used?

187

What is a Dead Letter Queue (DLQ)?

184

What is a slice? What is under the hood of a slice? How does the append function work?

184

// 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() }

Middle+
178

How was the figure of 25% calculated? Why not 20 or 30?

176

What is Mutex and RWMutex? How do they differ?

175

How does the garbage collector in Go work? When does it run? Can it be run manually?

173

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 }

Middle+
172

What are strings in Go? What do they represent under the hood?

169

What profiling tools are available in Go?

167

What is struct alignment in Go? How to optimize struct fields for memory?

166

Were there any nuances and difficulties in implementing Kafka? Was it your first experience?

166
/3