Today learnt about securing webhooks with HMAC
1. Create signature:
sig = HMAC(secret, JSON.stringify(payload))
2. Send it in header:
X-Signature: sig
3. On receive, recompute & compare:
expected === received
secret = a shared private key (known only to sender & receiver).
yesterday’s plane crash shattered something deep within me. not just because lives were lost, but because stories vanished in a moment. a family, scattered across borders, had finally reunited to fly to london. they were just trying to be together. two british tourists, drawn to the soul of india, had spent weeks exploring its culture. they were on their way home. a girl, the first from her village to land a job in london, was heading toward a new beginning. another was simply visiting her nani, carrying nothing but love. and in one instant, all of it ended.
we spend our lives making plans, postponing conversations, saving our affection for some later day. but the truth is that we never really know when we’ve said our last hello, our last i love you, our final see you soon. today might be the last time you laugh with a friend, fight with your partner, or hug your mother. we move through life like we’re invincible. we’re not. we’re fragile, perishable, and utterly human.
and it is in that fragility that life becomes most profound. not because it lasts forever, but because it doesn’t. it is short, unpredictable, and it asks of us a quiet kind of courage to live fully, love freely, and speak gently while we can. so say it now. call them now. forgive where you can. feel everything. hold the people you love a little tighter.
because in the end, what remains is not time, but memory. and memory only lives when we choose to be present before everything slips away. so love like you're running out of time, because one day, without warning, the world will go on and you won’t get to say goodbye.
Once I was reviewing a code and I found that at multiple places the joins were avoided in favor of multiple selects ⚡ Upon asking, I got the response - joins are expensive and we should avoid them 🤦♂️
This is not true at all. Let me debunk the myth and give you a way to understand the costs involved.
Joins are expensive, but only when the data we are joining is huge, or your table lacks the right indexes, or when we are joining a large number of tables (>12). A join query can always be substituted with multiple select statements, but you may end up with an n+1 query problem.
Select statements are great but remember every select statement you fire, needs to go to the database over the network and come back to the client. Each query requires connection establishment, query parsing, query execution, disk access, and data transfer.
Even if the statement looks simple, the overhead of network roundtrip and query execution over multiple retrievals is substantial; and in most transactional cases will be greater than the cost of a join query.
A single join query completes the same task in a single shot. Thus one round trip, one-time query parsing, query optimization, and execution and you get the intended result.
Coming back to the incident, we replaced multiple select with a join and the response time of API was reduced from 1.2 seconds to 152ms. Pretty amazing.
Again, this is contextual to the data we had and the use case we were solving. So, instead of blindly following some tips and advice you hear on the internet, it is better to benchmark it on your own codebase and pick the better one.
Beware when someone says such generalized statements; take them with a pinch of salt. Knowing the nuances makes you a better engineer.
ps: admissions open for sys design feb cohort - https://t.co/nnhcj5gQzH
#AsliEngineering #SystemDesign