The Hypertext Transfer Protocol (HTTP) is the foundation of data communication on the web. Although HTTP/1.1 has been a standard since 1997, many web developers don’t fully utilize its advanced features for optimized performance. In this post, I’ll explain some key capabilities in HTTP 1.1 and how to leverage them.
Best Practices for Express Middleware Management
When structuring Express apps, middleware play a crucial role in handling cross-cutting concerns like logging, security, and error handling. However, as our middleware chain grows, managing the installation order can quickly become messy. In this post, I’ll go over a few patterns for installing Express middleware - from simple to more advanced - and discuss the pros and cons of each approach. The goal is to provide some ideas and best practices to keep our middleware pipeline maintainable as our app grows.
Troubleshooting in Practice - connection leak detection as an example
Introduction
As of the writing time, I have been working for over five years. In recent years, with the gradual accumulation of work experience, more and more colleagues and peers have approached me for help in solving challenging problems, such as Node.js memory leak detection, database connection pool leak detection (where connections are held for a long period), performance optimization, deadlock detection, among others. Today, I will use database connection pool leak detection as an example to summarize a set of approaches for troubleshooting complex issues for future reference - my best practices to troubleshooting.
Overall, my approach to analyzing complex issues can be broken down into eight steps.
Error Handling in Practice - Centralizing Operational Errors in Node.js
Introduction
In the ever-evolving realm of software development, errors and exceptions are constant companions. These errors can be broadly categorized into two types: programming errors and operational errors. While programming errors are typically caught during development and testing phases, operational errors are the real-world hurdles that applications must gracefully navigate in production environments. In this blog, we will shine a spotlight on the art of handling operational errors and delve into the pivotal role played by a central error class in Node.js.
DDIA reading notes - chapter 7 Transactions
Chapter 6 of this book discusses Transactions. For decades, transactions have been the mechanism of choice for simplifying these issues. A transaction is a way for an application to group several reads and writes together into a logical unit. Conceptually, all the reads and writes in a transaction are executed as one operation: either the entire transaction succeeds (commit) or it fails(abort, rollback).
Transactions are created with a purpose: to simplify the programming model for applications accessing a database. By using transactions, the application is free to ignore specific potential error scenarios and concurrency issues.
DDIA reading notes - chapter 6 Partitioning
Chapter 6 of this book discusses the concept of data partitioning. The chapter explains how data partitioning can be used to improve the scalability and performance of distributed systems. The author describes various partitioning techniques and their advantages and disadvantages. The chapter also covers the challenges that arise when partitioning data, such as data skew and hotspots, and explains how to mitigate these issues. Overall, Chapter 6 provides a comprehensive overview of the partitioning strategies that can be used in modern distributed systems.
DDIA reading notes - chapter 5 Replication (Part II)
Last section of Chapter 5 is Leaderless Replication. Leaderless Replication is a different approach compared to Single Leader Replication and Multi-Leader Replication, abandoning the concept of a leader and allowing any replica to directly accept writes from clients. In some leaderless replication implementations, the client directly sends its writes to several replicas, while in others, a coordinator node does this on behalf of the client.
DDIA reading notes - chapter 5 Replication (Part I)
Chapter 5 of this book covers the important topic of replication in the context of database systems. Replication is the process of creating and maintaining multiple copies of the same database on different servers. This is done to ensure data availability, improve performance, and provide fault tolerance.
The chapter starts by introducing the concept of replication and its benefits. It then goes on to explain the different types of replication, including master-slave, master-master, and multi-master replication. Each type is discussed in detail, with its advantages and disadvantages.
DDIA reading notes - chapter 4 Encoding & Evolution
This chapter focuses on the challenges of encoding and evolving data formats in distributed systems.
The chapter begins by discussing how data formats can impact system design and evolution. It then explores two common approaches to data encoding: binary encoding and text encoding. Binary encoding is more efficient but less human-readable, while text encoding is less efficient but more human-readable.
使用 OpenAPI 设计 RESTful API (一)
0x00. OpenAPI 简介
在之前的文章 Restful API 设计指导 中,我介绍了如何设计 Restful API。随着前后端的分离以及软件架构的复杂化,你是否也遇到过以下的一个或者多个问题呢?
- API 的设计和实现并非同一个人。无论是在大型互联网架构中还是复杂的软件开发中,API 的设计往往是有架构师、资深工程师、PM 等这些经验丰富的人负责。一旦设计完成,才将具体的开发任务分配给相应的 API 开发工程师。
- API 有完整的测试。越是复杂的产品,对产品的质量有越高的要求,一般而言会有专门的测试团队对 API 进行完整的自动化测试。
- 前端开发工程师(或者 API 的调用方)和 API 工程师协同开发,因此前端工程师需要 Mock API 以解除对 API 开发进度的依赖。