Posts
Parties in Online Advertising
I am going to give a talk highlighting elementary concepts in online advertising. It is a good time to review all the basics.
DSP Demand-side platforms receive an ad request that they must answer by a time set by the SSP or ad exchange. The time allowed can be as low as 100 ms and range up to a few seconds. DSPs decide whether they want to bid. If they do, they must select an ad, determine a bid price, and return their offer to the ad exchange.
Posts
Beware of Backpressure
One of my junior dev was frustrated today. He was supposed to read from a file stream with NodeJS, piping that into the database. However, he got errors thrown everywhere when dealing with larger files. I helped him identified the problem. He had been dumping async calls (the database insertion) faster than the call could be handled.
I remotely remember I run into a similar issue years ago when I wrote a web scraper in NodeJS.
Posts
Compress Url Parameters Without a Storage
In advertising and other online marketing fields, a common practice is to distribute URLs to the clients so that they can report user action through a simple GET request.
Those parameters are fake. But you got the idea. Longer URLs mean higher bandwidth consumption. Moreover, if your URL is too long, you will risk triggering Error 413: request entity too large. I know nginx throws it.
Posts
Purposed PHP Dialect: P++
The first time I saw P++ my reaction was “meh, it is not going anywhere”. Anything breaks backward compatibility and abandons existing user base will get punished eventually. Python community took a decade to heal from the wound caused by Python3. In short, I believe it is not worth it to trade backward compatibility for language design purity. I also wrote a blog about Vue3 changes on its new functional APIs.
Posts
Rethink The Clean Architecture
The Clean Architecture is more like a fantasy. It is like a wonderland we will never be in.
I would enjoy and appreciate a work where all business domains, application domains, and transports and UIs, etc. are all orthogonal. In reality, they are all wired together like a mess. It is no mess created by engineer though. The world is chaotic by itself, so do all the business around it. Imagine your boss tell your team to add a new button to your website, and you find your business rule doesn’t cover this button what so ever, so you have to update your JSON API, add new test cases, and add new event to your event sourcing bus, and change whatever is affected all the way down to the database level.
Posts
Unboxing Taylor Otwell's Laravel Cloud
Taylor Otwell, the author of Laravel, recently put up a public copy of his unfinished work Laravel Cloud in GitHub. It was taken down by himself briefly after, due to what he described as “too much BS”. Forks are still available everywhere though. Here is my fork.
I cloned the repository and skimmed through most of the classes. Here are my takeaways.
Dependency Injection is used very lightly. The service container is mostly underfilled.
Posts
Contextual Dependency Injection Is a Myth
Sometimes in your daily programming life, you would want to inject different object instances based on the current route or module. For example, you want to connect to Database Foo for route /foo and Database Bar for route /bar. It seems a clever idea to do what is called a “contextual binding”, aka inject instances conditionally based on some runtime value.
In Laravel it looks like this:
<?php $this->app->when(PhotoController::class) ->needs(Filesystem::class) ->give(function () { return Storage::disk('local'); }); $this->app->when([VideoController::class, UploadController::class]) ->needs(Filesystem::class) ->give(function () { return Storage::disk('s3'); }); This code looks nice and handy at first glance, but in my experience, they are often doing more harm than any good.
Posts
Kubernetes on Premise: Top 5 Fallacies (Part One)
As the saying goes, Kubernetes is gradually eating the world of software. In the last year, we have switched our on premise infrastructure from Docker Swarm to Kubernetes. Adopting Kubernetes on the cloud is one thing; adopting it on premise and making it production ready is quite another. Many lessons have been learned along our journey. For those who have played with Kubernetes in the vacuum, there are probably some hidden deadly trap yet to be revealed.
Posts
Never Force Yourself to Learn New Skills Without a Concrete Project
As the job demand is going nowhere in a decade, a lot of new guys want to get into programming. There are numerous courses online, teaching a variety of skills in programming. There are also new shinning frameworks climbing up GitHub trending every day. I see a lot of people, typically newly graduated students, get confused. There seems to be an endless stream of knowledge to learn. How many skills are enough?
Posts
Ad Server Rewrite: Goals and Non Goals
We have carried out the first or maybe last round of rewrite of the Juhui DSP/SSP/ADX with Typescript. A few goals and non-goals have been set for this labor-intensive process.
Goals Strong typed. Strong API contracts. Holistic Observability with logging, tracing, and metrics. Layered Architecture and dedicated component. Testcases can be run by anyone. Stateless over stateful. Improved readability. Proper code deprecation process. Non-Goals Use fancy technology.
Posts
Epoll and Event Loop: Just Enough You Need for Interview
The biggest challenge for intermediate developers to understand event loop is that the articles found around the web are either written for die-hard C programmers or simply too long to read. I will give a try on explaining the event loop/epoll(), and stop at a point where interviewers will be sufficiently satisfied.
The first thing should be made crystal clear is that things happen on two sides: The kernel and the userspace.
Posts
Transactions Are Not Atomic
MySQL (InnoDB) transactions are ACID, with A for atomicity.
An atomic transaction is an indivisible and irreducible series of database operations such that either all occur, or nothing occurs
The atomicity here is different from the atomicity in concurrent programming.
An operation acting on shared memory is atomic if it completes in a single step relative to other threads.
Suppose you want to read a number from a column, add it by an offset, and write it back to the same column.