Unique Indexes: We Should Think Twice (Especially at Scale)

In “Big Tech” environments (you know, the kind with tons of users, massive datasets, and rapidly evolving requirements), relying on database UNIQUE INDEX constraints to prevent duplicate data—unless it’s for something like financial reconciliation where every penny must be exact—honestly, might not be as effective as you think. Plus, the cost of maintaining them can be surprisingly high. A better approach is often to handle the bulk of deduplication logic at the application layer. If you can avoid using a database unique index, consider doing so, or at least think it through very carefully before implementing one. ...

May 16, 2025 · 8 min · Zhiya

JWT Pitfalls Guide: Solving the nbf Verification Failure Issue

Phenomenon A freshly issued JWT becomes invalid when used in the next request, resulting in a 422 error. { "msg": "The token is not yet valid (nbf)" } If you wait a few seconds before making the request again (for example, using Chrome Developer Tools’ Replay XHR), it succeeds. Principle of the nbf Field Looking at the error message above, you will notice an nbf, which is a field in the JWT protocol. It stands for Not Before, indicating that the JWT Token is invalid before this time, and is generally set to the issuance time. This raises a hypothesis: in a multi-server environment, if the servers’ times are not synchronized, a token issued by one server might fail verification on another server due to the nbf field. The JWT protocol has already considered such issues, and it specifically mentions using a small leeway to address this in the nbf section. ...

March 26, 2019 · 4 min · Zhiya

User Authentication Practice Based on JWT + Refresh Token

HTTP is a stateless protocol, meaning once a request is completed, the server doesn’t know who sent the next request (the same IP doesn’t represent the same user). In web applications, user authentication and authorization are crucial, and there are multiple practical solutions, each with its own merits. Session-Based Session Management In the early development of web applications, most adopted session-based session management, which works as follows: ...

December 13, 2018 · 6 min · Zhiya

SSH Tunneling Through ngrok

ngrok To access a host using SSH, if you are on the same local network as the host or if the host has a public IP, you can connect directly using the SSH command with the host’s IP address. However, most companies and homes use local networks and cannot assign a public IP to each host within the network. In such cases, network tunneling is needed to connect to hosts within a local network from the outside. ...

December 10, 2018 · 2 min · Zhiya

Unicode and UTF-8

The concepts of Unicode and UTF-8 are fundamental and important, yet they are often overlooked. Character Set In computer systems, all data is stored in binary, and all operations are represented in binary. Human languages and symbols also need to be converted into binary form to be stored in computers, which necessitates a mapping table from human language to binary encoding. This mapping table is called a character set. ...

December 7, 2018 · 3 min · Zhiya