The Strategy Pattern - allows us to define a family of algorithms (strategies), put each in a separate struct, and make them interchangeable at runtime.
Instead of hardcoding logic with if/else or switch, you encapsulate algorithms and let clients choose dynamically. #golang
A cache is a high-speed data storage layer that stores a subset of data so future requests are served faster. Instead of going to the slow source (DB, disk, API), we serve from cache. #SystemDesign#SoftwareDevelopment
With pooling , a connection is created once.
It’s kept alive and stored in a pool of idle connections.
Future requests can reuse this connection, skipping the setup cost.
This makes HTTP clients faster and more efficient.
we use connection pooling to reuse existing network connections (like TCP) instead of creating a new one for every request.
Normally, making a new HTTP request involves:
1. DNS lookup
2. TCP handshake
3. TLS handshake
These steps are slow. #golang#Networking
Maps: nil is Readable, But Not Writable
1.) A nil map has no underlying hash table.
2.) You can safely read from it → missing keys just return the zero value.
3.) You cannot write to it → writing panics because there’s no storage yet (use make to create one).
Slices: nil is Safe & Useful
1.) A nil slice behaves like an empty one.
2.) A nil slice just means the pointer inside the descriptor is nil, length=0, cap=0.
In languages like Java/C++, we rely heavily on inheritance:
class Dog extends Animal { ... }
But Go takes a different approach - composition through embedding. #golang#SoftwareDevelopment
Scaling presence at large scale (millions of users):
1.) Use WebSockets for real-time connections.
2.) Store state in Redis (fast in-memory lookup).
3.) Use pub/sub to instantly notify others when presence changes.
How online presence works:
1.) When a user connects → client sends a heartbeat (ping) to the server every few seconds.
2.) If heartbeats stop → user marked offline after a timeout.
3.) Status is broadcasted to friends/chat participants.
#SystemDesign
Consumers can still read all values already in the buffer.
They stop only when the channel is fully drained.
Closing ≠ deleting the data - it just means no new values can be sent.
#Golang#Channels
In Go, a channel with fixed buffer size can handle many values.
we can think of it like a pipe with backpressure:
> Producer waits when pipe is full
> Consumer drains, then producer continues
Buffer size ≠ total capacity
#golang#Concurrency#SoftwareEngineering