Solving A Subscriber's Golang Interview Assignment!

  Рет қаралды 9,424

Anthony GG

Anthony GG

Күн бұрын

► Join my Discord community for free education 👉 / discord
► Become a Patreon for exclusive tutorials 👉 / anthonygg_
► Follow me on Twitter 👉 / anthdm
► Follow me on GitHub 👉 github.com/anthdm
In this video, I'm going to implement my solution for a real Golang interview assignment that was asked of one of my subscribers. The main goal of the assignment is to implement a caching mechanism to prevent database overload.
#golang #programming

Пікірлер: 39
@anthonygg_
@anthonygg_ Жыл бұрын
► Join my Discord community for free education 👉 discord.com/invite/bDy8t4b3Rz ► Become a Patreon for exclusive tutorials 👉 www.patreon.com/anthonygg_ Thanks for watching
@noone-gz4pc
@noone-gz4pc 3 ай бұрын
Hey man, so much respect, thanks for the high quality content, you inspired me to keep learning go!
@timdithmer9184
@timdithmer9184 Жыл бұрын
Love the "Go for a solution, don''t make yourself even more problems"-message Great videos, love the content, keep up that amazing work!
@anthonygg_
@anthonygg_ Жыл бұрын
Thanks
@syamprasad6038
@syamprasad6038 Жыл бұрын
now, my mind is not in my control, I hope you understand my situation, but, still, I watched the entire video, it doesn't matter whether I understood it or not, I am just mesmerized by how a person can fight a problem. It's really a motivational video than a technical one. Hmm, what I want to say is, ok man, You are excellent. Hope you will do more real-world problems and it's solutions, why I am saying this is I have never seen such a KZbinr who solves real-world problems. All are solving odd, even, palindrome, Egypt pyramids.... ohhhhh bullllshit
@anthonygg_
@anthonygg_ Жыл бұрын
Thanks!
@SaiVikram-tv5fj
@SaiVikram-tv5fj 8 ай бұрын
​@@anthonygg_could you share the GitHub link for this project
@jorisjansen2892
@jorisjansen2892 Жыл бұрын
More caching and Go information, great!
@joebuydem
@joebuydem Жыл бұрын
I think this is a great concept to teach. Real world interview questions.
@interstellar1873
@interstellar1873 Жыл бұрын
Great content as usual 🔥 Thanks Anthony for everything you do for the community 💯
@jainilshah7907
@jainilshah7907 Жыл бұрын
When I start watching your video not able to stop expecting more and more of this kind of video, you are amazing man
@robertomoreno7906
@robertomoreno7906 10 ай бұрын
Thanks for the content. Though, I think that this is the very first level in a job interview. Follow up question from the interviewer is how do you handle concurrent writes and reads to the cached map ('db' map in this example). Also would be interesting to see how would fix concurrent miss hits to the same user id (in a real case scenario, database access takes time could be the case) and caching invalidation. I know that you can not explain everything in a 20m video but these are very common interesting scenarios to solve and would be amazing to see your take :)
@damaroro
@damaroro Жыл бұрын
dude you got new subscriber , i'm looking forward to see more educational content from your videos
@anthonygg_
@anthonygg_ Жыл бұрын
Thanks my man 🙏
@TheSupahG
@TheSupahG Жыл бұрын
amazing tutorial! thanks a lot!
@abdorootuae
@abdorootuae 7 ай бұрын
Your are changing mentalities 👏 thanks
@daltonyon
@daltonyon 4 ай бұрын
Great video, I like your approach, "less is more"! I learn something with this video and the junior even more. Curious, past year I interview some devs and most of them forget to write a good "README" on how to execute they solution, I spent a lot of time looking how to execute and test they application!!
@helloworld7796
@helloworld7796 Жыл бұрын
As a software engineer with 15+ yrs of experience, I can confirm that you will have to do in real life only 1 or twice. 1 in the interview (maybe), and 1 more time in a real project, if you dont want an existing solutions and want to have more fun/stress in your life. Aside from that, awesome content!
@JustAnand078
@JustAnand078 7 ай бұрын
Great explanation
@shivaakrish
@shivaakrish 9 ай бұрын
Excellent content!
@sc76399
@sc76399 11 ай бұрын
Could have dockerized the solution but that's a really simple solution you came up with and that's what I think separates the juniors and experienced Devs an elegant but simple solution
@rayhanmahmudshihab
@rayhanmahmudshihab Жыл бұрын
I really love your videos man. Thanks so much for all these amazing contents. I'd like to add a follow up question. Q: If we handle caching by using map, how can we write this in a thread-safe way? Let's say we also want to impose a limit for concurrent map element access. If limit == 10, we will allow 10 cocurrent access at most at any given time.
@Chemaclass
@Chemaclass Ай бұрын
Great solution
@faisalmushtaq2287
@faisalmushtaq2287 Жыл бұрын
more like this please.
@diegonicacio
@diegonicacio Жыл бұрын
Great explanation, very helpful! One thing that I was wondering was that the assignment specifically asked us to "Create a library" , which I believe means that the idea was to create something that could be imported into another project and act as a caching mechanism + database middleware? If that was the case, even since the core logic is already implemented, this means the interviewer could end up failing us on the test, right?
@anthonygg_
@anthonygg_ Жыл бұрын
The library thing not really makes sense to me as I mentioned in the beginning of the video. You cannot make a middleware library without knowing how they are using their database internally in their codebase. So I think solving the problem here is the most important. Making a library after knowing the details is super easy and does not prove anything.
@ragasanov
@ragasanov Жыл бұрын
Hey, great video. I am learning go coming from the other language and have a question. Why the test panics if you remove time.Sleep for a millisecond? I expected a WaitGroup to be responsible for finishing goroutines. And having a sleep feels hacky, but I can't figure out why this hack is needed? Cheers
@Chips4Real1
@Chips4Real1 Жыл бұрын
quality content
@cristianortiznavia7595
@cristianortiznavia7595 Жыл бұрын
Awesome.. just that, there is more interview question solved so smootly like this one?
@Wouter0100
@Wouter0100 Жыл бұрын
But.. what if 2 requests arrive at the same time? Due to concurrency, this _is_ possible. Especially in the case where thousands of requests arrive per second, as described in the assignment. I think this also makes the question most interesting - as this is the challenging part. Even in this case where thousands of requests come in, you want to hit the database only once. I'd say that part of this would be that you lock a caching key, and let all other requests wait for that key to be released - after which the cache will be populated and ready to be used for the specified caching key. For example, this is something mailgun's groupcache implementation is doing by default.
@anthonygg_
@anthonygg_ Жыл бұрын
100 % agree. In a real world production env. We would use a distributed cache with a distributed lock.
@user-rs4sg2tz6k
@user-rs4sg2tz6k Жыл бұрын
So 1. Check if the user is in the cache, just send the response with it. 2. If there isn't, append it to the (short period(maybe few milisecs) existing) list(response and request body pair) that for hitting the database. If the list is full or the short time is arounded, the list will be sent concurrently and eventually delayed back with response from the database. + we need to clean the cache by its capacity or some period time.
@madlep
@madlep 9 ай бұрын
There's the programming interview answer - which I'd do by having a second "pending" map containing channels wait and to be sent a result if there is already one in flight. Then there's the real world answer, which is just have a regular cache, but put metrics around it, and IF it turns out additional requests on the same key while the initial request is still running is a problem, THEN you implement the fancy fix. But before that, you'd probably want to make sure you've got a database connection pools etc set up properly, because that probably solves 99% of that 1% problem anyway. If you're getting into distributed caches, and distributed locks, you need to be *really* sure you need it and you know what you're doing. The overhead of replicating that distributed state and waiting on it in a pessimistic manner is probably far greater than any gain from work saved by not doing extra work querying the same key before the local cache is initially populated.
@af2b
@af2b Ай бұрын
Hi Anthony, everything good? can you share your extensions of your vscode? thanks!
@TommyBeingaDik
@TommyBeingaDik Жыл бұрын
Bro, you should teach to my university ♥️
@anthonygg_
@anthonygg_ Жыл бұрын
❤️
@richardwng
@richardwng Жыл бұрын
Gigachad cache, used this method once before. Love it!
@anthonygg_
@anthonygg_ Жыл бұрын
Great to hear!
Important Tips On How To Write Idiomatic Code In Golang
21:52
Anthony GG
Рет қаралды 20 М.
How To Use Goroutines For Aggregating Data In Golang?!
17:15
Anthony GG
Рет қаралды 34 М.
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 58 МЛН
Китайка и Пчелка 10 серия😂😆
00:19
KITAYKA
Рет қаралды 2 МЛН
100❤️
00:20
Nonomen ノノメン
Рет қаралды 66 МЛН
I Nailed Every Coding Interview With This Secret Trick
10:43
Anthony GG
Рет қаралды 6 М.
The Hidden Cost Of GraphQL And NodeJS
28:35
ThePrimeTime
Рет қаралды 182 М.
Golang's Mocking Techniques - Kyle Yost | hatchpad Huddle
41:20
How To Build A Custom TCP Server In Golang!?
19:32
Anthony GG
Рет қаралды 23 М.
How To Build A Chat And Data Feed With WebSockets In Golang?
20:45
I Reviewed The Perfect GOLANG Assignment Until This Happened
17:10
Golang Slice Tricks Every Beginner Should Know
15:46
Anthony GG
Рет қаралды 8 М.
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 58 МЛН