I was watching FlashForward – a TV show focused on high-concept narrative around a mysterious event, that caused nearly everyone on the planet to simultaneously lose consciousness for 137 seconds, during which time people see what appears to be a vision of their own life approximately six months in the future: a global “flashforward“. It boggled my mind. 2020 pandemic reminds me a lot like that. A black swan at global scale. Nobody, not even the brightest of minds on this planet, could have predicted that. Well, Bill Gates did. But that’s debatable.
As I survived through the pandemic, I feel fortunate and grateful to be surrounded by the people I love, who made the over-long lockdown worthwhile. The black devastating year was a great teacher, and a living testament of my emotional intelligence – patience, perseverance, pluck, and compassion. Someone once asked me, if I have learned anything at all. So let me tell you what I learned. I have learned that nothing in life is permanent. I have learned that nothing can replace the pain of losing a loved one. Life is fickle. Everybody dies at the end. But if we mean something to someone, if we loved someone, we are not truly gone. As long as our memories remain in the heart of those we love, our tales are told, our music is listened, our books are read, our paintings are admired, a part of us, though little, continues to live in this world. I have learned that happiness can be found in darkest of times. I have learned that little things in life can be beautiful beyond imagination. Sitting on the porch, and watching the sun fade into the sky – lying on the rooftop, and counting the stars as they emerge from the blanket of darkness – strolling on the crosswalk, holding hands of a loved one, while they whisper something in your ear – enjoying exquisite delicacies someone you prepared only for you. I have learned that nature always finds a way to heal itself. Covid19, while it deeply scarred the lives of people across the globe, there are things in nature which we never realized were there. Dolphins returned to Venice. Himalayan ranges can be seen from certain parts of Punjab. Clear blue skies, vibrant sunsets — colours that I so wanted to see in Hyderabad for the last 7 years– were all here. I have learned that you can find love in weirdest of places in weirdest of ways. And that lockdowns can be beautiful. Nothing can really replace the feeling of spending the moments with someone you love. No materialistic thing in this world is, and will ever, be capable of that. I have learned that sometimes we should follow our hearts, and take its guidance. If you want to meet someone, spend time with someone, never ever think twice. Life rarely gives a second chance. I have learned that as you grow, the number of friends trims down. Fake and pretentious people leave, and those who are true remain. It’s a process of selection.
Having lived a good part of the year in silent contemplation of various aspects of life, I’ve come to realize that nothing in life holds permanent. A year filled with pain of losing a loved one, joy of finding new love, opportunities missed, chances not taken (which sometimes never come), decisions – good and bad, lost friends, regrets. I realized that life is fickle after-all. Humans are minuscule in grand scheme of things, and sometimes we don’t have a choice. All we can do is wait, and watch events unfold in mysterious unpredictable ways.
Last year was truly special because of two major events in my life. I met a wonderful woman, Keeya, my life partner, because of whom the lockdown turned out to be the best gift I could’ve asked for. I also took a difficult decision relocating to North American shore. As much deeply as I want to pen about it, perhaps it’s a long story for another time.
When everything is over, when the worst has happened… there’s still one thing left in Pandora’s box — hope — hope that everything will be okay. It has to be. It’s a cycle of life.
March 23, 2020 – A date that still sends the shivers down me. I saw my net worth plummet like a rock to 47%. Nifty was at 7600, and I just didn’t know how to react. Wonderful businesses were selling at throw away prices, and I had no clue if I should buy or sell. As I reminisce those unprecedented times, I am fortunate to have held onto the businesses I believed in. I kept calm, and pretended I was living under a rock, as if nothing has happened. Albeit my floccinaucinihilipilification of the market bottom lost me a multi-decadal opportunity, the feeling of coming out of it unscathed is unparalleled, and can’t be expressed in words. Patience is the silent acceptance that things can unfold in a different order than planned.
As we’re at the fag end of an unfortunate year, here is a list of things I learned in 2020.
It is often when one least expects it that fate arrives at our door. We can’t foresee it any more than we can escape it. No matter how hard we run or hide, fate, like death, will always find us. You can’t always plan for unprecedented times. Be flexible. Learn to adapt
You don’t seek love. Oftentimes, you find it in weirdest of places in weirdest of times
You don’t find excellence. You build it and then it takes you places
Developed countries are not always developed in everything. The first thing that I missed in Vancouver is the disruption from Mukesh Ambani in India
Loneliness is real. It’s hard to make friends abroad
Stay away from pretentious, dishonest people. They suck all your energy and positivity. If you spot a pathological liar, run as far, and as fast as you can
The colour of Autumn is worth all the hype. Despite being ephemeral, and a showstopper of destruction, it oozes positivity. I realize why writers have been musing over romantic October evenings, Cinnamon brown leaves, benches filled with dried leaves, for eons.
Life doesn’t always give second chances
Plan for FIRE as early in your life as you can. Timing the market is a futile exercise. Time in the market matters
Lockdowns can be beautiful – if you’re stuck with the right person
Be grateful for the good health you got. Other things in life may not hold much value, if you’re not healthy
Never ever tie your happiness with wealth. Your wealth can erode in a single unfortunate day
Cheers to yet another year! And remember, Anni, amori e bicchieri di vino, nun se contano mai – “Years, Lovers and Glasses of wine… these are the things never to be counted”
I am writing this, from my apartment, scared, and defiant, trying to adjust myself to the new realities of life and finding calm in the chaos. My brain still can’t handle the fact that we’ve been caught up, in-between what they call, once-in-a-century pandemic. Spanish flu, infamous as pandemic of twentieth century, infected one-third of the world’s population. And today, we are struck again by a novel virus.
Bill Gates — “The next outbreak? We’re not ready”
Interestingly, Bill Gates had warned us about an outbreak like this in one of his TED talks, dated April 3rd, 2015.
If anything kills over 10 million people in the next few decades, it’s most likely to be a highly infectious virus rather than a war. Not missiles, but microbes. Now, part of the reason for this is that we’ve invested a huge amount in nuclear deterrents. But we’ve actually invested very little in a system to stop an epidemic. We’re not ready for the next epidemic. The failure to prepare could allow the next epidemic to be dramatically more devastating than Ebola.
Ebola killed about 10,000 people that year, and nearly all were in the three West African countries. Because of nature of the virus, it didn’t spread more. Ebola does not spread through the air. And by the time you’re contagious, most people are so sick that they’re bedridden.
So next time, we might not be so lucky. You can have a virus where people feel well enough while they’re infectious that they get on a plane or they go to a market. The source of the virus could be a natural epidemic like Ebola, or it could be bioterrorism. So there are things that would literally make things a thousand times worse. In fact, let’s look at a model of a virus spread through the air, like the Spanish Flu back in 1918. So here’s what would happen: It would spread throughout the world very, very quickly. And you can see over 30 million people died from that epidemic. So this is a serious problem. We should be concerned.
In fact, if there’s one positive thing that can come out of the Ebola epidemic, it’s that it can serve as an early warning, a wake-up call, to get ready. If we start now, we can be ready for the next epidemic.
From Bill’s Ted talk
How bad is this?
Covid-19, a name rarely heard three months ago, is on the lips, and in the mind, of every living individual on the planet today. Coronavirus fear is deepening in our hearts, with each passing day, forcing us to reassess our priorities. The panic is real. The threat is real. I am waking up to new heart wrenching numbers every morning. The day isn’t far, when it would reach every nook and corner of the world. Soon, each one of us, may know at least one infected person. We could have contained it. But we didn’t. USA downplayed it. So did Italy, and Spain. Countries with 2003 outbreak scars, seemed to control it well — South Korea, Singapore, and Hong Kong — until cases started rising again.
As I type this, USA and Italy have surpassed China’s numbers, with Italy — “The China of Europe” — accounting for one-third of world’s Coronavirus death toll. It has only begun, far from done, pushing the world into a fresh recession, as bad, or worse than, 2008, and challenging & overwhelming world class healthcare system. If this is the situation in developed countries, I can’t seem to think what would happen in India, for it scares the hell out of me. I suspect the official numbers may be vastly dwarfed by the actual numbers. 21 days lock down is only a beginning. After effects will be far worse, and daunting. The blog — Coronavirus: Why You Must Act Now — says a lot of things, things one should know.
We can mitigate it
Exploding number of cases is blowing whistles and raising alarm across the globe. It took 67 days to reach the first 100k, 11 days for the next 100k and 4 days for the next 100k. Before it becomes catastrophic, uncontrollable (are we already there?) and renders us into history — like World War – II, 9/11 — it needs to be taken very seriously. And for that, each one of us, have to play our part seriously, patiently, and wisely. One infected person can reignite the sparks in regions where we have successfully extinguished the fire. We still don’t understand the virus enough. It took nearly twenty months to find a cure of less 2003 outbreak. We have got one chance of saving the humanity, going into flames, by doing nothing. Let’s not waste the opportunity. Do what a hero does in situations like these. Please stay home. World War – II and 9/11 have given us enough scars. We don’t need a third one. As they say, nothing lasts forever. We will come out of this, stronger and better. It’s a war of resilience, more than the fittest.
Is technology making it worse?
The advancement in technology has greatly eased our lives. But it comes with side effects. Coronavirus originated from Wuhan, a province in China. Before we took it seriously, we had cases in every other country and territory in the world. We are more connected than ever. Cheaper air travel and change in how we run businesses, exposed us to greater risk of spreading the virus much much faster. The question is not, who or what to blame. The question is, how do make best use of the technology in our hands, while avoiding its side effects.
Coping up with stress and anxiety
News channels and social media, flooded with Coronavirus, are polluting air with distress. With all these around, the question is, how do we cope up with stress, anxiety and fear. Once a hypothesis has become a reality. What-if is shadowed by Now-what.
I’ve been staying at home since March 20th, have stepped outside for groceries only twice for short while. I am writing, playing Piano and reconnecting with people I lost touch with. Most of the conversation I have over audio/video calls, revolves around the pandemic. I am trying hard to hold my sanity altogether — to not allow my mind to wander in distress. I am keeping my hope up — the darkness will clear up, and the sun will shine again.
Coronavirus is giving you a gift, The gift of time — To rekindle relationships, To spend time with your loved ones, To read a book, To reflect on your priorities, To realize there are far more important things in life than money — A gift of self realization. Use it before it’s gone.
How are you coping up with the situation? Let’s share and stay strong. This too, shall pass.
February 14, 2020 Kristen, It’s not very often that someone you talk to, intrigues and fascinates you in ways you never felt before. There was something in you, that charmed me in no time, like a magician playing tricks, effortlessly in front of awestruck audience. I am unsure of what it was that rendered me, spellbound, while talking to you. If I were to arrange it, in words, in the best of my abilities, I would picture you as a wave, crashing on the shores, making people go crazy, and want more of you. The most valuable art known to me, is the skill to keep the conversation moving. And, with you, it’s effortless, like a daily habit. I can talk to you for hours, and hours, and hours, and yet, it’s never enough. These days, my mind entertains nothing, but the thought of you. It’s irresistible to wait till next morning to hear your voice, one more time. Once a free bird, is now captivated by your enchanting voice, never to be freed again. When did I fall so deeply under your spell, Kristen. It’s hard to tell the time, or the moment. What I know is that I was already smitten by you, the moment I realized.
I always wondered, how two people end up spending rest of their lives together without getting bored. And then I met you. I have started to believe that rarely in your life, the stars align, and you get lucky enough to come across someone just perfect for you, who sets your heart on fire. And suddenly, you can’t imagine your life without her.
I have fallen head over heels in love with you, baby. I love you as bees love flowers and poets love poetry. I love you as icebergs love ship and fireflies love night. I love you as deserts love rain and drunkards love alcohol. I love you as cruises love seas and musicians love chords. You flew like the autumn in my life with your pleasant refreshing breeze, and rendered me, colorful and significant. You’re to me, what water is to fishes. The potency of this love has no bounds, and I only wish, that some day, I would be able to carve it into words — for this small writing is vastly dwarfed by what I feel for you.
September 25, 2018 Mary, A thing in particular I don’t like about life is that sometimes, we get to know someone deeply only to realize later it wasn’t bound to last and a time comes when we have to let it go. It all starts as fun. We screw up sleeps only to live an extra hour in that enchantment. Slowly it grips us in its storm and before we know, it throws us to the other side of the emotional landscape where golden sunshines are annihilated by gloomy thunderstorms, pleasant autumns are taken over by harsh winters and rays of hope are veiled by incessant rains.
been said that people our hearts beat for leave a part of them in us marking
our souls forever. I know our time was as ephemeral as all beautiful things in
the world are. But if there was a moment ever when my presence brought upon
your face a smile, my words made you chuckle and my voice comforted you in
times of distress, I will assume my existence in this universe has made a mark
upon your soul.
love, Mary? Is it the sum of all beautiful moments we had? Is love sweet? If it
is, why is it that your love is hurting me like hell. Why is that, that thing
in your life soured all the things we promised each other? Was our love that
weak, Mary? Was it that brittle?
would never measure upto what I feel for you. Before I met you, I used to spend
nights in silent contemplation of the void in my life. Looking up at the stars,
and the moon in lonely nights, I wondered when my life would be miraculous. And
then “us” happened. Your presence filled my dormant life with joy.
How will I wake up without the crack of your sweet voice?
This is probably the last letter you’ll receive from me. I won’t be writing any more letters to you, for my mind has subdued my heart. All those letters you read were penned with heart, hence they might have felt real. Had mind interfered in between, there would have been a lot of logic, and calculation, and psychology, and words won’t have been the same.
Years, lovers and glasses of wine must never be counted
Another year has
passed. My quest to seek the meaning of life and true source of happiness
continues. A question oftentimes pop up my mind, what would you do if you get a
chance to design your life the way you want. Would you still choose to do the
same work? Would you prefer more friends or solitude? Who would you want to
wake beside to? Would you stop chasing money and start earning experiences
instead? Possibilities are endless.
I wish life had a
pause button so that I could enjoy precious moments longer. It has been said
that when you want something, all the universe conspires in helping you to make
it true. I wonder why it never works with me.
If I paint the picture of 2019 highlights, it would be rendered quite vivid and colorful. 5 countries, few photography accolades (invited for guest talk at photography exhibition and others) and encounter with a sweet girl. Experiencing coldest day of my life, -13 degrees Celsius in the Swiss Alps and much awaited family vacation after 16 long years were icing on the cake.
However, there weren’t only sunshine and roses. I had my own share of rains and thorns too. There was a time when my life became directionless. I didn’t enjoy the work like I did before. The girl I was talking to vanished. Photography didn’t fascinate me anymore. There was nothing much to look forward to. I vividly remember spending days staring at the ceiling of my room doing nothing. These are the kind of days when you contemplate on missing aspects of life, chances you took, opportunities you missed, decisions you regret, people you lost, moments you wish to relive, successes, failures, so on and so forth.
Here is a list of 21
things I learned in 2019:
People always leave
You don’t find excellence. You build it and then it takes you places
Financial knowledge is something you can’t ignore. You are gonna need it at some point in life. And when you do, you would regret how much you have already lost
Sometimes you give your best and yet you fail
Things can go well when you least expect it
Sooner or later you succeed. You just need to keep trying
Some things in life are inevitable. You can’t change them no matter how hard you try. But you can always prepare to minimize surprises
Never lose people who were with you in the dark times. That’s when you know their true colors
Life of chances always trumps life with regrets. Wear confidence, take calculated risks and be expressive. Had I done it 5 years ago, my life would have been different
Trust is a rare thing in this world. Truth is, people who harm you are the ones you put most of your trust in. They change and so do their behavior towards you
If you have a secret, don’t tell anyone
You can be a nice guy and yet lose the girl
When you feel left out, there is always a community out there you can connect to
You always sacrifice one thing at the expense of other. It’s a zero sum game
You are human. You can’t work with the same efficiency all the time. But people would expect you to
Sometimes you don’t measure up to your own past performances
Family trips are awesome. You should do it whenever you get the chance
Buy only what you need
Car is not an investment. It’s an expense at the cost of comfort and luxury
Family, friends, work, hobbies — You get to choose any three
Life rarely unfolds the way you plan and anticipate
Happy new year! And remember, Years, Lovers and Glasses of wine… these are the things never to be counted.
August 29, 2018 Mary, The night is darker and lonelier than ever. I find a weird grave quietness in the air, the kind when the storm settles down silencing everything around. In this time of the hour, I wonder if you’ve gradually become my muse, for everything I write these days revolves around you. I am unsure if it’s your lingering charm or your stupendous attitude that I’ve started loving the darkness of silos and the only sound my mind entertains is of scribbling on my decade old rusty diary.
When did I fall so deeply under your spell, Mary? I’m probably at loss of words. There is a fundamental reason on why we fall for someone so easily, for the same reason we fall in love with stars and billion years old objects at first sight. There are forces in this world that can’t be reasoned with. And we mortals are weak in matters of heart.
July 26, 2018 Mary, You have destroyed me in the most beautiful way possible. My nights are restless. The days are better neither. Meeting you, I now know what’s it like to be in love. These days, my mind doesn’t entertain the thought of anything but you. I long for you as drought longs for rain.
Many years have
passed. I still remember every small detail of our first meeting — the leaves
falling in silence, the gentle breeze caressing your sun kissed brown hair,
your blue dress embroidered with round golden pearls and your angelic face
lighted up in joy. That morning, the nature had chosen the finest brush from
her collection, dipped it in my favorite color of the year and painted the
whole scenery cinnamon brown. It was as if she was preparing the perfect
backdrop since a very long time for me to meet you. Everything was so perfect.
If I have to choose one day from my life to go back to over and over again,
And how can I forget that magical evening over coffee. Deeply lost in conversation, we were barely touching our cups. Time flew and before we realized, it was already an hour. You asked, “Shall we leave?”, and then looked me into the eyes. You instantly knew I wanted to spend more time with you. Open shade in the blue hour took place of the coffee table. We spent hours sitting there, completing each other’s sentences and contemplating on what the future might look like. If only some astronomical event had stopped the earth from spinning around its axis, I would have spent countless days, weeks, months talking to you. Because with you, it’s never enough.
Of all the blockers of dynamism, I have known comfort zone to be the deadliest. For it gives us a false hope that the place and position we are in, is perfect. A poison for growth mindset I would say. Once we stay somewhere for 5+ years, it becomes a home for us. Home is hard to leave. For it renders us with a feeling of fulfillment.
Being a creature of habit, my behavior lately exhibits every sign of a person in comfort zone. I have never been quite fond of change. I am staying in the same flat for the last five years, driving the same car to work through the same route. Every person at the restaurant I visit knows my taste buds and all I have to say is, “The same cuisine I order always, please”. Microsoft has been my home for close to six years now.
This has greatly distanced me from the real world. Silent contemplation in lonely nights on these aspects renders me anxious. The Tech world is changing and so are the requirements. Not having slightest of clue on how the water tastes outside and where I stand, I said yes when an opportunity knocked my door tenth time since my college days.
When it all started?
It was a lazy friday noon. Winds blew hot, burning skin of people it touched. Sitting idle, my eyes alighted on a mail from a recruiter at the company. As usual, I responded that I was content with my work and things were going well for me. She asked me to just have a phone conversation and if things looked fascinating, we could move forward. I said, “Yes”. After all, what harm could one phone call have done. Must I say, she was very convincing.
This was supposed to be just a phone call until it became really interesting. Things like fantastic opportunities, work culture, smart engineers and location preferences were presented. In exchange, I talked about the work I have been doing at Microsoft.
Being no different from screening rounds of other companies, the focus was mainly to judge if my skills are worth time of their great engineers. Call it a first level of check. Basic questions to test Algorithmic + Coding + Mathematical skills — Quick sort, Merge sort, Hashing, Powers of 2, Tree traversals etc. I got a call next day that they can move to the interview process.
Video call – Round #1
The first DP problem on the face gave me sweats I find myself unable to pen in words even today. A simple problem, anyone with decent practice could have solved in 5 minutes.
Count number of ways to divide an array of n balls in k non-empty subsets.
After few failed attempts, I came up with a working recurrence relation: Number of ways would be: Put (k – 1) balls in n sunsets and remaining one in any of n sunsets + Put (k – 1) balls in (n – 1) subsets and remaining one in the empty subset f(n, k) = f(n, k – 1) * kC1 + f(n – 1, k – 1)
I didn’t do very well in this round as my first few formulae didn’t work and I took few hints to come up with the right solution. However, I was able to write the working code very fast, which turned to my advantage. The feedback was shared in 2 hours that I exhibited good potential. My coding was fast. But I needed to practice more. Since it was an onsite opportunity, they asked for another round.
Video call – Round #2
A fairly simple problem to find a missing character in two words. They kept on tweaking the problem, adding more constraints and complexity along the way. I wrote code for three approaches.
Onsite (Finally), phew…
I wasn’t quite sure if I would be able to make to onsite. I was disappointed of my performance and I needed a break to get over frustration. A visit to hometown seemed to be the most logical decision, which I later regretted after wasting thousands of bucks on flight tickets. One lazy Friday evening in office, when I was doing some code review, my recruiter informed me over call that they can move ahead with the onsite process. I was wildly surprised. She mentioned that she didn’t want me to spend the weekend in worry and hence, shared the happy news as soon as she could.
They booked my flight and hotel tickets. We talked for several days about my travel arrangements, preparation and any queries I had in mind.
The D day
Time flies. The D day arrived sooner than I had anticipated. I landed in the evening, checked in to the hotel, had a lavish dinner and slept like a baby to prep myself for the next big day.
In order to avoid last minute rush, especially in a place I had never been before, I arrived an hour early. The lobby was decor’ed with statues of slim geeks in skinny jeans holding mobile phones in their hands, emphasizing the direction the current generation is going and the core focus of the company. Beside me was a digital display with an array of tiles which flipped every couple of seconds showcasing that the company cares about Diversity and Inclusion. There wasn’t a slightest of fear on what’s gonna happen next. Instead my mind was puzzled with how the tiles were working. Ah! So they have multiple threads delivering the content to the tiles sitting in UI. The threads may never be sitting idle as the text appearing the those tiles as keyboard inputs. Or may be this is an illusion of parallelism as the context switch is so fast.
A guy in his early 30s, wearing a broad smile and a pony hanging on his back broke my reverie. “Are you Aashish?”, his voice was as fresh as morning dew. Having done some research about him on LinkedIn, “Yes”, I knew who I was talking to. “Hi! I am sorry I’m late by 30 seconds. I took a wrong turn. Hope you didn’t have to wait long.”, he smiled, “Let us walk to the interview room, shall we?”. There was a passion in his tone of voice. A passion that I have seen in very few people I have interacted with in my life so far.
We walked in a small meeting room. A white board was walled on the left, a table for 4 positioned in the center and a laptop connected to a projector on the right. We spent the first few minutes knowing about his background, his work and his team. “You’ve been given two words A and B. How many minimum concatenations of word A is needed to form subsequence B?”, he explained the problem with one example. Despite solving few problems on subsequences in the past, I had never heard of this pattern of problem before. It wasn’t a surprise. The company was wildly famous for asking new problems. And if not, they would tweak it to the extent it becomes new.
I started with asking questions to understand the scope of the problem. “Will the words contain only ASCII characters How long can be the words? Can they fit in one machine? What do we return if no concatenation can make a desired subsequence? etc” The first approach that popped up my mind was to put all characters of word A in a set and check if it contains every character from word B. Once it’s certain that a solution exists, I played with two pointers pointing to words A and B and wrapping around pointer to word A to the beginning when we fall short of characters. The minimum concatenation is the count of wrapping done. The time complexity of this solution is O(lenA x lenB).
While the above approach worked fine, the time complexity wasn’t great. I proposed another solution to create a map of characters to their indices (unordered_map<char, list<int>>) in word A. Now instead of linearly looking for a character from word B in A, a binary search in the map would reduce the time complexity to logA. One key point to take care was to make sure we are picking the next index from where we left of and increment the count of minimum concatenation at right time. upper_bound method worked like a charm. The time complexity reduced to O(log(lenA) x lenB).
“Sounds great. Do you want to code it?”, he seemed fine with the approach. The code was pretty straight forward to write. He took a look at the implementation, went through various corner cases and finally said, “Great, we have 5 more minutes. If you have any question about the company, the team or anything else, fire at me.” The company being a leader in Scalability, I was curious to know how they dealt with various challenges they faced and learning from it. Work-life balance, company culture, healthy environment, quality of work were other topics we discussed. He wished me good luck for the next round and left.
Ralf isn’t a Computer Scientist. But his quote holds true for every aspect of engineering I know of. The beauty of the world lies in design. But we are not here to talk about how Lamborghini design is better than its rivals or why Tesla is winning over the world. Well, not today.
System Design has been a hype for quite long and for all the right reasons. It’s the core of every business & technical strategy and the success behind every company.
I only got time to gulp some water before a guy with notebook in his hand walked in. Bald, mature & experienced look, he seemed like the kind of person people would want to go for seeking expert opinions. “So how did your first round go?”, he broke the ice. “It was great”, I said cheerfully. “Well, that’s rare here. I usually hear responses like, it was okay or I don’t know.”, he said, “Hope it went as good as you said”, he further added. “Are you aware of what a System Design is.”, he asked, “Have you ever used FaceBook or Yelp checkin system? I want you to design that.”, he continued without waiting for my answer. Guess it was a rhetorical question. “Before we start, let me tell you that I would most probably not ask you to write any code. So feel free to fire all complex and advanced data Structures that pop in your mind. “
As all design discussions start, I began with understanding the scope of the system. Users would tap on the Add location and it would show the list of 10 nearest location to choose from. The check in status would then be saved on the server. Delivering the status to user’s friends was out of scope. It’s good to have high availability and low latency for good user experience in a system like this. Availability can have an edge over Consistency. If a user doesn’t see a newly added location for sometime, it should be okay. He wanted me to come up with numbers. It was important, especially when you design something of FB scale. How many people, how many daily active users, how many locations, the size of database, number of machines, network bandwidth etc. So, there are 2.2 billion users. Let’s say we have 70% (1.5 billion) DAU and 30% of them checkin at least once a day. There can be hot users as well. Let’s worry about them later. The locations can be anything from coffee shops to hospitals to parks to big shopping complexes. All locations can be stored in a database. “How many locations do you think there can be?”, he chimed in. Umm, there are around ‘X’ places in the world and each place can have an average of ‘Y’ locations… “Don’t you think that it would make more sense to calculate the number of locations based on the world population rather than geographical area?” Ah, yes! The world population is 7 billion and there can be one location on an average per hundred people. We agreed upon 700 millions locations. “Which type of database will you use to store the locations? How many machines do you need?” I calculated the size of data to deal with and explained sharding can be done over LocationId in NoSQL. Calculation of network bandwidth with that data and machine config I was given (128 Gig, Octa core) gave an idea on the number of machines needed. Performance numbers talked by Jeff Dean was of great help. When the user taps on the search location, latitude and longitude will be send to the server… “Okay! How would you fetch the 10 nearest locations of a user?” Well, locations can be added to a Graph in memory and… “What if there is no node in Graph corresponding to user location? What if a user is standing in the middle of a street?” Umm… The whole structure can be seen as a 2D plane with four quadrants. Locations can be read from DB and organized in memory in Quad tree. Nodes at each level would be connected through a Linked List. Looking for nearest location would boil down to Quad-nary search based on user location where we discard three children at each level as we narrow down the search. If a node doesn’t have enough locations, we would check its siblings/cousins, maintain a max heap of size 10 and return the result. “Can you improve it further?” I think we can use K Dimensional tree as well. Unlike Quad tree, we don’t need to fork exactly in the middle. “So how does the whole flow look like?” I drew a high level design on the white board where the user location is sent from client to an Application server. The App server then passes the location to a NearestLocationFinder engine. Result is passed back to user. User checks in. The checkin data is sent to another Application server. Since the checkin data can contain huge bits like images and videos, the App server would put the checkin data in a Message Queue. We would spin off few workers to pick entries from Message Queue and write to a Database. We would need two Load Balancers. One for each Application server.
We further discussed on dealing with SPOF (Single Point of Failure) through replica, pros & cons of Master – Master and Master – Slave models. A caching mechanism in place (something like Memcached) for low latency to display user checkin history.
Forty minutes just flew. As usual, the interview ended up with me asking few questions around Scalability. Having realized many things that can go wrong in a design of humongous scale, “How often do you calculate these numbers? Are they very accurate?”, I asked in wonder. “We do work with numbers. But they aren’t always correct. It takes a lot of experience”, he replied, “Good luck with your next interview”, and he left.
The interviews so far had been a breeze. Discussing interesting problems is always fascinating and mind boggling. In no time, the third interviewer walked in, introduced himself, the team he was working on and other cool stuffs. A simple problem on expression evaluation, except it had a twist on how Compilers work. State Automata quickly struck my mind like a bolt of lightning. I drew few states to parse and switch between the states based on input. He mostly emphasized on why I used Data Structure ‘X’ over ‘Y’. Coding was simple and I had to use map and Stack. That’s the beauty of state machine. Once there is a working diagram, coding doesn’t take much efforts.
“Let’s try to break the code”, he smiled while going through the code. I looked for every possible corner case that crossed my mind and each one of them seemed to be covered. “What if one of the numbers is 0?”, he looked at me. “Damn!” In the heat of discussing big things, I missed to handle critical divide by zero error. Albeit I fixed it quickly, I think the harm was done.
A person with no expression on his face was waiting outside to take me to lunch. He looked very well acquainted with the environment and the work place, probably because of spending many years there. We quickly rushed to the cafeteria. An array of delicious cuisines, varying from Indian to Italian to Mediterranean to every other I could think of, accompanied with drinks and deserts. I wish it weren’t an interview day and I were there with an empty belly & mind void of any thought. While taking a stroll in the beautiful campus post lunch, we crossed meditation room, music hall decor’ed with Grand Piano & other instruments, very strange shaped offices fostering creativity. Filled with awe, we entered a room that looked like forest. Trees peeking from the left, tiny waterfall gliding softly in the corner, birds chirping over the branches. In the center was lying a young girl doing something on her laptop. I was amazed and blown away.
A glimpse of the amazing campus pushed me to give my best. I met another cool guy who asked a problem on finding nearest favorite city of a user. “I am not, in particular, looking for a solution. I am looking for ideas”, he added.
I asked few questions to understand the scale at play — How many cities can there be? Can we fit all of them in one machine? I threw some Algorithm (which I don’t remember) in the beginning. While I was explaining on the board, a variation of Dijkshtra’s popped up my mind which seemed to work well. He was fine with it. I also added some preprocessing to optimize the Algorithm as the cities don’t change very frequently. Writing code took another 5 minutes. “How often would you preprocess the data?”,he asked. In the times when there is less load on the server, like once every 24 hours. “Don’t you think it will hamper accuracy?”. Yes, it’ll. But not very far. It will help users get data in reasonable time window. User experience matters. The error in system exists even today. Maps wasn’t able to detect the new U turn for weeks.
I was happy and content until he added the twist. “How would you improve it?”, he smiled. This was the most optimal solution that crossed my mind there. Luckily while skimming through my FB newsfeed few months back, I watched a video on comparison of Djikshtra’s and heuristics based A* Algorithm. “We can use some heuristics to scope the search instead of going haywire. I remember reading about A* Algorithm in my graduation days.”, I felt relaxed. I could see him smiling. It looked like this was what he was looking for. So if the direction of favorite city of the user lies South, we can bail out the Algo and not explore the North. There can be a possibility that we have a rocky road in the direction we are looking and there is a faster way if we take the opposite direction and use a newly constructed flyover. “This is a good practical solution. Not everytime we want the perfect accurate result. There is a careful balance between accuracy and latency”, he smiled. We discussed few other practical approaches, few things on and collection of data and ML.
The best interview of the day, I could feel it from the conversation with him. He was widely impressed. “So tell me about the things you do at Microsoft. I went through your resume and it was pretty impressive”, he said. “Microsoft is a great company. Smart people, awesome culture. To be honest, I don’t find anything bad there. If I had, I won’t have stayed 5 years there”, I responded. We discussed some of the work I was doing without violating any NDA.
Round #5 — The final battle
There is a saying, “All is well that ends well”. No matter what I do, I can’t seem to annihilate those 45 minutes of my life. Rooted deep inside the neurons of my brain, it hurts even today and makes me wonder how I could have done it any better.
DP has always been my nightmare. No matter how many problems I solve, a new one still surprises me. I was greeted by an Indian guy in the last round. Unlike other interviewers, he, without any talk, rushed to a problem which had some made up story on Cargo, men and packages. I recognized it in an instant. It was a complex version of famous Painter Partition problem. A fairly difficult problem for people who haven’t practiced DP well. I gave a brute force exponential solution and explained on the white board followed by for-for-for DP solution. I, then with some example, pictured on the board how the table would be filled. He seemed fine with the approach and asked to code. That’s where things went south. A recursive solution was easier and straight forward. I could have just written the brute force solution I had explained in the beginning and stored the result in a table to optimize. It was a win-win situation. But No! I had to cripple myself to death.
Beaming with confidence, I started writing for-for-for iterative solution and explaining what each line of code was supposed to do along the way. I made critical off-by-one error and another error in calculation where a column was being added the way I didn’t want to. I also felt irritated that even after explaining Algo twice — Once on the white board, later while writing code, he was wasting time in asking things I had already explained. This didn’t happen in any other round and I would never expect it from someone working at a company of that stature. I, however was able to correct one of the errors and was close to fixing second when he asked me to write the recursion solution. Something I could have done in the first place without suffering any agony. “Let bygones be bygones”, I sighed, took a deep breath and wrote the perfect working solution in single attempt, all within 3 minutes. I just needed another minute to store the result in a table. But the time was over. If only he had cooperated more, I had performed better. And as I had guessed, he, without any talk, took me out of the building.
If I do an assessment of my performance, I did good in first, not sure about second, okay in third, great in fourth and not good in fifth. Interview process was a breeze and as smooth as butter. I was pretty impressed with how well organized everything was.
Please feel free to ask any question, except the name of the company 🙂
Not long back, popularity of Yahoo Messenger was at its peak. Google mail was in diapers, to be subscribed only through invitation. A time when TheFaceBook was to see light of the day and WhatsApp was never heard. Late in night, when I have nothing much to do, often I contemplate on the Tech advancement I have witnessed ever since I knew what software was. Please don’t take off your seat just yet, I am not gonna take you back to medieval age when computers sat only on the desks of rich people.
It was 2006 when I got my first PC. 256 MB DDR1 RAM, 20 GB HDD, single core processor. It’s fascinating to see users and how they use devices & services have come a long way. SaaS (Software as aService) is on the top of mind. The world is going paperless and companies which are scared of moving to cloud may fray. With overwhelming 24 billions devices connected to internet today, the emphasis on Scalability has become more than it ever was. The amount of data we produce is enthralling and mind-boggling – that’s 2.5 quintillion bytes of data per day. 90% of all the data till date was generated over the last two years. It is everywhere – AI, Machine Learning, self driving cars, home automation system. It’s the future.
Consumers, today, don’t care which Operating System they use, which device they hold in their hands and how much power those devices are packed with. They just want Software and services to work like a charm.
Every company, if they are to take the world with the storm (read Google Search, WhatsApp or MS Office) they are building, has to tackle two things eventually – Scalability and Cross Platform strategy. I would scope this blog to Scalability and leave the latter for some other day.
So what’s Scalability?
You are the founder of a finance company, often dealing with clients (read it people). Clients come to you for your hassle free, time bounded services. They are happy because you promise them to get the work done in 3 working days. That’s how you make money. For one year, you are pretty much happy. Happy clients, happy you. No big deal. More people hear about your services through word of mouth. And soon enough, you are flooded with clients from all over the world. You compromise sleeps and start working overtime. This works well for another five months before you realize that you can’t work alone. You hire more people, as beefy and efficient as you. Because businesses run on trust. You can’t just say that you don’t have time. People stop coming when you no longer provide what you promise. Scalability is when you can serve the requests in the reasonable time window by hiring more resources. Bigger hard drives, more RAM, powerful processor (more cores). That’s vertical scaling. But there is a limit on how much resources you can add to a machine. Costs go up and there comes a point when buying a new machine is cheaper and more feasible. That’s horizontal scaling.
In the next part, I would touch upon Databases, Caching, Message Queue, Sharding and few other topics before delving into System Design problem space. Stay tuned!
The universe has always been a mystery to mankind. Scientists compromise sleeps in the pursuit to discover the next earth. While few people like me, look forward to see their wishes come true upon seeing a falling star. But no matter who we are, there is something mysterious in the stars that astound us in one way or the other.