Locking using Redis, Communication with Non Tech, First Job vs Master Degree
Application Locking using Redis SETNX with TTL, Communication tips with non-tech people, get first job or master degree
Welcome to the first episode of TIL (Today I Learn). We will have 3 real-world questions about Software Engineers topics such as: system design, softskill, leadership, career advice and more…
To receive full access and support The Scalable, consider to subscribe us if you haven’t already!
Quick Link:
Solving Race Condition using Redis SETNX with TTL
Question
I have a backend API service called 'transaction-api' that manages all transactions within our company. Under the 'transaction-api,' there is a worker that runs every 10 seconds to check for any pending transactions. If a pending transaction is found, the worker communicates with a third party and updates the status based on the response received.
The problem is that we have recently scaled our 'transaction-api' horizontally (now 5 servers). I have noticed that race conditions occur, leading to inconsistencies in our data. How can we resolve this issue without splitting the services?
Answer
Basically, what you need to do to solve that kind of race condition is throught application locking. The idea is, every server need to get the shared key to be able proceed the checking. For easy way, I suggest you to use Redis SETNX.
Redis can be used for locking purposes in the application layer to prevent race conditions. The SETNX
command with TTL can be utilized for this purpose. I have frequently utilized this approach, particularly in microservices architecture.
The SETNX
command ensures that the Redis key is only created if it does not already exist. This behavior allows us to use it for acquiring locks. The TTL (Time to Live) parameter is necessary to ensure that the Redis key is automatically deleted in case of any unexpected events, avoiding potential deadlocks. However, it is crucial to carefully consider the appropriate TTL value. It should always be greater than the maximum processing time to prevent race conditions from occurring.
Improve Communication: Speak Their Language
Question
Why it is hard to explaining things to non-tech people, we’ve always argue each other?
Answer
Most of the scenarios that make it seem difficult arise from a difference in wavelengths or understanding. One skill that interesting to solve this matter is “Speak their language”
We can observe this through the character of Tyrion Lannister in Game of Thrones. Despite being a dwarf and despised by his family, he manages to survive numerous challenging situations until the end. One of the main reasons for his success can be attributed to his mastery of communication.
One communication skill that Tyrion often employs is "Speaking in their Language." In a specific scene (S1E2), Tyrion is captured by a jailer and tries to persuade him to release him. He uses a tactic similar to the following in his attempt to convince the jailer (Mord).
Tyrion: “Sometimes posession is an abstract concept, when they captured me they took my purse, but the gold is still mine.”
The jailer is not convinced because he has a basic level of communication skills. At this point, Tyrion realizes that he needs to change how he communicates.
Tyrion: “Have you ever heard the phrase Rich as Lannister? Of course you have, I am Lannister, if you deliver message from me then I will in your debt. I will owe you gold”
After Tyrion tones down his level of communication, the jailer understand and becomes convinced by Tyrion and does what Tyrion wants. Therefore, when communicating with non-technical individuals, it is crucial to speak in their language.
Over to you, have you conducted any research on the individuals you communicate with?
Fresh Graduate: First Job or Master Degree
This question has been raised by several individuals whom I have encountered during my experience as a speaker at various universities.
Question
Q: I will soon graduate with a Computer Science degree. I have had an internship before and felt like I had a hard time following the senior staff, often performing poorly in my job. Do I need to pursue a master's degree (CS) before entering the job market?
Answer
I would suggest taking your first job, especially if your goal is to secure a Software Engineering position and excel in that role. Pursuing a master's degree will not necessarily guarantee success in your job. The reason is that there is a difference between acquiring new knowledge and applying that knowledge in a practical work environment. Real-world scenarios often differ significantly from theoretical concepts. While continuous learning is always beneficial, but in terms of efficiency, pursuing a master's degree before you gain work experience may not be the most efficient use of your time.
On the other hand, as you gain experience in your job, you can better relate the knowledge you acquired during your master's degree and apply it to enhance your skills and expertise in the workplace.
If you are finding it challenging to perform well, I suggest you to analyze what specific areas you may be lacking in. Is it technical skills, understanding project requirements, communication, or something else? Once you identify your areas of improvement, dedicate time and effort to address them. Improving will require investment and potentially utilizing your free time, such as weekends, to focus on enhancing those skills. Additionally, don't forget to leverage the expertise of senior staff members as valuable resources to support your growth and improvement.
Thank you for reading today's newsletter! If you find it valuable, don’t forget to: