A note in SSL/TLS

What is SSL? and why do we need them? SSL is a method to encrypt your data before transmitting it to the receiver. If we don’t encrypt and send data as plain text, somebody can sniff in your connection to read all your messages. How do SSL works? Of course, to establish an SSL, we need a TCP connection first, let’s assume that we have a TCP connection ready. How an SSL connection is established ...

June 5, 2022 · 5 min · 876 words · Khanh Bui

Is NodeJS really single-threaded?

No! Not really! NodeJS has one main thread called event-loop and it also has a worker pool to handle blocking IO and CPU-intensive tasks. The default number of threads in the worker pool is 4, and you can change it. Node.js uses a small number of threads to handle many clients. In Node.js there are two types of threads: one Event Loop (aka the main loop, main thread, event thread, etc.), and a pool of k Workers in a Worker Pool (aka the threadpool). ...

May 28, 2022 · 2 min · 236 words · Khanh Bui

HashCode VS Equals

To demonstrate what is the difference between object hash code and object equal, I would like to start with a simple example in Python. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 class Person: def __init__(self, name: str, age: int) -> None: self.name = name self.age = age def __repr__(self) -> str: return f'{self.name} {self.age}' john = Person('John', 18) eventRegister = {} # John want to join the event eventRegister[john] = True # In the next day, # he changes his mind john = Person('John', 18) eventRegister[john] = False print(f'registers: {eventRegister}') # Check john = Person('John', 18) print(f'Will John join the event? {eventRegister[john]}') It’s quite simple, right? I define a new Person class that has two properties age and name. And then I defined a map, to check if a person join the event or not. ...

March 27, 2022 · 4 min · 800 words · Khanh Bui

B tree, B+ tree, and indexing in database

B tree and B+ tree B tree is a self-balance tree. I can see that the B tree and AVL tree have a thing in common – it is all self-balance. But the difference is, each node in the AVL tree store exactly one value, and have at most two children. Each node of the B tree contains an array of at most N values and has at most N + 1 children. ...

January 9, 2022 · 4 min · 725 words · Khanh Bui

Isolation Level and Read Phenomena

1. Read phenomena When transaction A reads the data that might be changed by transaction B. 1.1 Dirty reads: Is when a transaction read uncommitted data from another transaction. Example: Transaction A Transaction B begin transaction; select age from employee where id = 1; // age = 24 begin transaction; update employee set age = 25 where id = 1; // age = 25 select age from employee where id = 1; // age = 25 rollback; select age from employee where id = 1; // age = 24 commit; 1.2 Non-repeatable reads When during a transaction, you retrieve a row two times, and the second time, you got a slightly different row. It is different from the dirty read in that this time, it read committed data. ...

January 2, 2022 · 3 min · 439 words · Khanh Bui

ACID

Atomicity: Each transaction could have multiple steps in it, each step might be a query or an update to the data. Atomicity means that the transaction is considered a success if all steps are a success. If just one of those steps is failed, the whole transaction is considered to fail, and it has to roll back to the previous state. Consistency: In the database, it might have some rules or constraints, and the transaction when modified data have to follow those constraints. For example, let say the constrain for bank account balance is 0 or positive, so if a transaction tries to assign a negative number to a bank account, it violates the constrain and has to roll back. ...

December 8, 2021 · 2 min · 251 words · Khanh Bui

What happens when you use a browser to access google.com

So this is just a quick recap of what I have learned about networking First, you have to connect your computer to the local network. Your computer then will be assigned a local IP by a DHCP server (Dynamic Host Configuration Protocol), you cannot use that local IP to talk to the outside network. All the devices in the same local network will use the IP of the gateway to talk to the internet, sometimes it’s called public IP. The protocol to map from local address to public address is called NAT (Network Address Translation). ...

December 7, 2021 · 3 min · 520 words · Khanh Bui