golang interview problems for senior role:
1. What are method sets? how do you decide when to use value receiver over pointer receiver?
2. How does the Go scheduler work? What happens during a goroutine context switch?
3. Explain escape analysis and provide examples where variables escape to the heap.
#golang
Most developers don’t struggle to FIND content.
We already have:
YouTube.
Docs.
Courses.
ChatGPT.
Notes.
The real problem?
We forget most of what we spend hours learning.
That’s why my friend built CodeVoice.
Link: https://t.co/q4YssGBj1b
A developer learning system designed to help you:
• capture concepts in your own words
• review before forgetting
• stay consistent for months
• retain knowledge long-term
Not another content platform.
Just a better way to make learning stick.
Try it for 7 days.
See if your learning finally starts staying with you.
New article: Slices, Maps, and Channels 🔥
A look at the three most ordinary Go types and the not-so-ordinary structures behind them.
↔ slice headers and the doubling/1.25× growth rule
↔ Swiss tables, H1/H2, and local growth
↔ hchan, sudogs, and direct goroutine handoff
👉 https://t.co/KqHc0T07TK
#golang #go
Reading this Paper on today
The Tail at Scale
Software techniques that tolerate latency variability are vital to building responsive large-scale Web services.
@denizumutdereli Viper is great for complex configs, but it’s a heavier dependency. godotenv is lightweight and does the job perfectly for simple .env loading.
If you've used joho/godotenv in Go, you probably have done this at the top of main.go
It works but there's a cleaner one-liner, trick with /joho/godotenv/autoload.
The blank identifier _ tells Go to just run init function from this package (autoload)
- Zero boilerplate
- loads before everything. init() runs before main(), so env vars are ready even for package-level var initializers.
- Great for scripts, demos and small scripts.
BUT DON'T USE THIS IN PRODUCTION:
- because it silently swallows errors. autoload calls godotenv.Load() and ignores the returned error.
- No control over order or path. Can't load .env.local or .env.production.
@rshdhere You can, but os.Getenv() doesn't parse .env files. it only reads vars that are already set in the environment.
godotenv lets you define them in a file and load them at runtime, which is handy for local dev.
Request Coalescing also known as request deduplication or singleflight.
It's a technique where multiple identical concurrent requests for the same resource are merged into a single underlying operation.
It prevents thundering herd or cache stampede.
Common domain where this matters:
- Cache refills after expiry (redis)
- CDN origin fetches for the same asset
- DNS lookups for the same hostname (Go's net package does this)
- Upstream API calls with rate limits
- Database queries during traffic spikes
pgx if you are on postgres and not planning to swap
lib/sql gives you portability. for most CRUD-heavy services it is genuinely enough. pgx gives you postgres. It shines when you need postgres-specific features COPY, arrays, custom types but if you are not using those, you are adding a dependency for features you don't touch.
I prefer manual implementation most of the time. I use golang-jwt/jwt for stateless authentication, bcrypt for password hashing.
Implement authentication as a reusable middleware that intercepts requests, validates the token/session, and adds user context to the request.
Another alternative is to import uber's auth package (https://t.co/vE7a9XorZY) for request authentication & Authorization for user-to-service and service-to-service communication.
There are some good go packages available such as:
Casbin: powerful library for Authorization (RBAC,ABAC, ACL).
Oauth2: official go package for OAuth2 client & server flows
Goth: popular package for multi-provider OAuth (Google, GitHub, Discord etc)
Some open source Identity servers like keycloak, casdoor etc.
SQL's NULLS FIRST and NULLS LAST
When you sort a column that has NULLs in it, your DB has to decide where those rows go. NULL is not zero. It is not empty. It means unknown, and unknown has no natural place in a sorted list.
Every database made its own call on this, and they disagree:
- PostgreSQL and Oracle put NULLs last on ASC, first on DESC.
- MySQL always puts NULLs first, no matter the direction.
- SQL Server puts NULLs first on ASC, last on DESC.
- BigQuery does the same as SQL Server.
So the same query on different databases returns rows in a different order, silently, with no error.
The fix is two simple keywords:
ORDER BY score DESC NULLS LAST;
ORDER BY score ASC NULLS FIRST;
You attach them after the sort direction and the database does exactly what you said. No surprises.
Where this actually needed:
Leaderboards where unranked players (NULL score) should not appear at the top above real scores.
Task lists sorted by due date where NULL means "no deadline" and should sit at the bottom, not above urgent work.
Paginated queries where an unstable sort causes rows to repeat or disappear across pages.
The catch: MySQL and SQL Server do not support the clause at all. The workaround is ugly but works:
ORDER BY CASE WHEN score IS NULL THEN 1 ELSE 0 END, score DESC;
This pushes NULLs to the bottom. The downside is it cannot use a column index, so on large tables it costs a full sort pass.
One index note for PostgreSQL users: if your query says NULLS LAST, your index should match. Build it as CREATE INDEX ON table (score DESC NULLS LAST) or the planner may skip it for the sort.
The rule is simple. If the column is nullable and the order of NULLs changes the meaning of your output, write it explicitly. The default is invisible, differs by database, and produces wrong results without telling you.
Distributed Locks :-
A distributed lock ensures that only one process or node across multiple instances can access a shared resource at a time.
Just like a Mutex but across a network.
In a distributed system, multiple instances of a service run simultaneously. Without coordination, they can process the same job twice, corrupt the shared state or race on cron jobs.
A good distributed lock must have properties like Mutual exclusion, Deadlock safety and Fault tolerance.