2024-02-14
- Starting to get the sense that music is similar to Anki as a hobby. The thing that stands out as similar is the amount of time you have to spend grinding before you feel like it is “paying off.” I think most hobbies I’ve explored have a “payoff” window (when you start to really get excited about doing it more, you feel like you “get it” and want to explore, etc) of like < 1 hr. Basically all board games and sports fall into this category. You start playing, and boom, you’re having fun, you “get it.” Then there are hobbies where you start to see payoff after like 10 hrs. Maybe cooking falls into this category? Or programming (like you could do a small, intro project in 10 hours of time spend)? But then there’s hobbies that take even longer. Some hobbies involve spending 100-1000 hrs before you start to really “get it” and it starts to become exciting/fun. Anki falls into this category. Running/lifting has elements of this too. And now, music kind of feels like that for me. It’s a
bit faster of a hobby to pick up than Anki, which took maybe 100 hours (?). With music, I think I started feeling a payoff at like ~50 hrs (all just wild estimates here btw). But the overall experience of payoff is reminiscent of Anki. Also, similar to Anki, I had to do multiple attempts to get into it. My first attempt(s) at both resulted in the hobbies not sticking. I didn’t “get it” in time, and I dropped the hobbies before trying again. But now, I do feel like I “get it” with music as a hobby, similar to Anki…and it’s great! But it makes me think about “payoff windows” a lot, and how it is relatively rare to be willing to stick with something for 50+ hours before you start to feel like it is making sense. The upside I think with even trying to go that long without a payoff is that these kinds of hobbies tend to be very deep. You’ll likely never run out of things to explore, and they will change the way you relate to many things in the world around you, which makes life much more
rich.
Notes
- System Design Interview — An Insider’s Guide
- Websockets reduce latency compared with polling bc there is no per-request HTTP overhead and updates can be delivered precisely when they are created without incurring a large polling load on the server
- Are HTTP connections persistent?
- Generally, no
- They can be in HTTP 1.1+ with the Keep-Alive header
- Cassandra is a good DB for write-heavy workloads
- What is a good DB for write-heavy workloads?
- Cassandra
- Others too, ofc, including relational DBs like MySQL, but this one was mentioned in the System Design interview book
- What is a standard, first-pass sharding approach you should consider if your data doesn’t fit in a single DB?
- Shard by user id
- This will often work right out the gate. The downside/risk is if load is not evenly distributed across users. If a small subset of users create a disproportionate load (e.g. Justin Bieber has many Twitter followers), then putting that user on a single shard can itself create a hotspot that is fragile.
- What hardware indicators are often used when deciding whether to scale out/up a system under load?
- Stuff like
- CPU usage
- Out of memory errors
- I/O thrashing/throttling
- network card saturation
- Are WebSocket servers traditionally “stateful” or “stateless”?
- Stateful
- This was mentioned in the chapter about a “Nearby Friends” service
- Note, the implication of this is that removing a WebSocket server has to be done carefully because the loss of state can affect other clients/servers/the general behavior of the system
- What is the risk when removing a “stateful” server from a distributed system?
- Other parts of the system will depend on the state in that server and operations or user-facing features might break if the state is lost
- An implication here is that the load balancer or cluster manager will have to maintain state itself for when a node is added or removed from stateful services. This could be something like a “draining” state for when a service is in the process of being removed and shouldn’t have any state-creating requests routed to it. Or a “syncing” state for when a new server is up and pulling necessary state from other servers and isn’t yet ready to serve requests.
- It is worth noting that effective auto-scaling of stateful servers is the job of a good load balancer. Most cloud load balancers handle this job very well.
- HTTP Headers: General Headers
Content-Type
- Specifies the media type of the resource or data being sent (e.g.,
text/html, application/json).
Content-Length
- The size of the response body in octets (8-bit bytes).
Date
- The date and time at which the message was sent.
- HTTP Headers: Request Headers
User-Agent
- Identifies the client software making the request to the server.
Accept
- Specifies the media types that the client is willing to receive from the server.
Accept-Language
- Preferred languages for the response content.
Authorization
- Credentials for authenticating the client to the server.
Cookie
- Sends stored cookies from the client to the server.
- HTTP Headers: Response Headers
Set-Cookie
- Instructs the client to store the cookie and send it in future requests to the server.
Server
- Information about the software used by the origin server.
WWW-Authenticate
- Indicates the authentication method that should be used to gain access to a resource.
Cache-Control
- Directives for caching mechanisms in both requests and responses.
- HTTP Headers: Security Headers
Content-Security-Policy (CSP)
- Helps prevent cross-site scripting (XSS), clickjacking, and other code injection attacks by specifying valid sources for resources.
Strict-Transport-Security (HSTS)
- Enforces secure (HTTPS) connections to the server.
X-Frame-Options
- Provides clickjacking protection by indicating whether or not a browser should be allowed to render a page in a
<frame>, <iframe>, <embed>, or <object>.
X-Content-Type-Options
- Prevents the browser from interpreting files as a different MIME type to what is specified in the
Content-Type header.
- HTTP Headers: Caching Headers
ETag
- A unique identifier for a specific version of a resource, allowing for more efficient caching and resource updates.
If-None-Match
- Allows a 304 Not Modified response to be returned if content is unchanged.
- HTTP Headers: WebSocket Headers
- Used in the WebSocket opening handshake. It’s part of the protocol to establish a WebSocket connection.
- HTTP Headers: Compression Headers
Accept-Encoding
- Specifies the encoding algorithms (e.g., gzip, deflate) that the client can understand.
Content-Encoding
- The type of encoding used on the data.
Date
February 14, 2024