Code Room
Code reviewHardcr-g352
Subject Api designLevel Senior–Staff~25 minCommon in Networking & APIs interviewsIndustries Software development, Technology

Question

Review this Go endpoint that creates a subscription. The mobile client retries on timeout.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewgo
func createSubscription(w http.ResponseWriter, r *http.Request) {    var req SubReq    json.NewDecoder(r.Body).Decode(&req)     sub := Subscription{        ID:       uuid.New().String(),        UserID:   req.UserID,        PlanID:   req.PlanID,        Created:  time.Now(),    }    if err := db.Insert(&sub); err != nil {        http.Error(w, "insert failed", 500)        return    }    billing.StartCycle(sub.ID) // schedules first invoice    writeJSON(w, 201, sub)}
Run or narrate your approach, then ask the coach.