SpinTheMic
Pro

Interview practice question

Lazy initialisation race

Backend Engineering · Concurrency · Intermediate

Your service lazily initialises an expensive client the first time it is needed, and sometimes two instances get created. How do you fix it?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • Check-then-create race.
  • Synchronised initialisation or lock.
  • Language helpers (sync.Once, Lazy<T>).
  • Initialise eagerly at startup.
  • Double-checked locking needs volatile.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics