Last Updated: May 22, 2026
A lot of expensive setup work in an online store happens exactly once over the lifetime of a process: parsing a config file, opening the database connection pool, building a discount-rules table from disk, loading the product taxonomy into memory. If several goroutines hit that setup path at the same time, you need a way to make sure only one of them does the work and the rest wait for it. sync.Once is the standard primitive for that job.