Retry creates duplicate subscription
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.
0:00 of about 25 min
Mark a line and say what kind of problem it is.0 findings
1func createSubscription(w http.ResponseWriter, r *http.Request) {
2 var req SubReq
3 json.NewDecoder(r.Body).Decode(&req)
4
5 sub := Subscription{
6 ID: uuid.New().String(),
7 UserID: req.UserID,
8 PlanID: req.PlanID,
9 Created: time.Now(),
10 }
11 if err := db.Insert(&sub); err != nil {
12 http.Error(w, "insert failed", 500)
13 return
14 }
15 billing.StartCycle(sub.ID) // schedules first invoice
16 writeJSON(w, 201, sub)
17}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.