Feng's Notes Isn't coding fun?
Posts with the tag Backend:

A Subtle NestJS Dependency Injection Pitfall: Request-Scoped Providers in Background Workers

Recently our team ran into a production incident caused by a subtle interaction in NestJS’s dependency injection system.

The root cause was a request-scoped provider being injected into a service that was also used by a background worker. At first glance the code looked perfectly valid, but the runtime behavior was very different from what we expected.

This article explains:

  • what happened
  • why it happens in NestJS
  • how dependency scope propagation works
  • how to design services to avoid this class of issue

Building Smarter Rate Limits in NestJS with Redis

When you build APIs that bill per token—like AI workloads—rate limiting stops being just a traffic control feature.

It becomes a revenue-protection mechanism.

We learned this the hard way: if you let users run multiple concurrent AI tasks before their token usage is reconciled, you can lose real money.

So we started from NestJS’s built-in throttler, explored Redis-based options, and eventually built our own token-bucket limiter with Lua.

This post walks through that decision process—what works, what doesn’t, and how to evolve your rate limiting when you move from simple backend requests to token-based billing.

Troubleshooting Cloudflare Image Upload with Node

I was working on testing upload images to Cloudflare using their API. The task was supposed to be simple because cloudfare have some code samples here, however I was having trouble getting it to work. As I’m using node+axios , the sample code on document is like

How to Test a Kong Plugin

Kong is a popular API gateway we are proactively using. Sometimes we need to develop plugins to meet specific architecture/business needs.

Kong Vs Goku

最近由于工作需要用到API网关做请求转发用,挑了目前人气较高的两款 Kong 和Goku 对比研究一下。

分布式事务与最终一致性

为什么需要分布式事务

先摆一个例子: A账户要向B账户转账,100元, 操作的步骤是

A账户先减掉100元
B账户再加上100元

写一个并发请求的Case

有些场景下,你可能要检查代码有没有并发问题,验证幂等或者做一下简单的压力测试, 这时候需要写一个并发请求的程序,那么怎么做呢?

What you need to know for memory-leaks troubleshooting(排查内存泄漏你需要知道的套路)

内存泄漏是一个比较棘手的问题,大多数时候没有明显的报错,这给问题排查带来很大困难,好在前人已经遇到很多类似问题,也留下了一些典型的排查套路,大部分时候只需要按图索骥,一步步来即可。

My take on distributed system(我所理解的分布式调度)

我所理解的分布式调度

对于规模以上的应用来说,调度系统已经是必不可少的组成部分,尤其在基于数据分析的后台应用大量增长的今天,健壮的调度任务管理已经是非常重要的一环,因此多花些时间来分析研究调度系统的设计对于日常的开发与运维具有比较重要的意义。

调度问题是怎么来的

当你的网站是个简单的blog,而且并不需要跟外部交互的时候,你大概不需要调度任务,因为此时网站需要处理的任务仅限于 即时交互 , 即用户想使用一个功能,你就立即给他就是了,如同你在简书上写一篇文章,一点保存,这篇文章立即就保存到网站的后台服务器中去了,这也是互联网刚出现时候的最早的应用模式。