Skip to main content

Ads Ecosystem

· One min read

Ads Ecosystem

  • Brand / Advertiser: individuals or organizations who want to publish advertising messages to the customers.

  • Agency: they help the brand to interact with the rest of the ecosystem and manage the whole lifecycle of the advertising messages, including planning, creating, and distributing ad campaigns.

  • Trading Desk: It streamlines the media buying process.

  • Demand-side Platform (DSP): it automates online ad inventory and buying, helping agencies to manage accounts across different accounts and campaigns through one platform.

  • Data-management Platform (DMP)

    1. Ads-based Analytics: attrition, targeting, profiling, session replay, and more.
    2. Anti-fraud
    3. Market-based Analytics
  • Ad Exchange / Real-time Bidding (RTB): It matches ads suppliers with buyers.

  • Ad Network: It aggregates publisher inventory and sells it to advertisers.

  • Supply Side Platform (SSP): It monitors the entire ads inventory and suggest prices for ad space.

  • Publisher: Ad-space owners like website operators.

Canadians Complain About Online Payment Systems

· One min read

Since 1990, the internet's 402 Payment Required status code has been designed, yet nearly thirty years later, online payments still do not provide a seamless experience.

  1. I saw an article online and just wanted to pay to support it, but you made me create an account, set a password, fill in my credit card number, and then I get bombarded with endless spam.
  2. Payments should be as convenient as browsing—one-click payments without needing to fill in an account, just using crypto tokens. However, centralized payments are monopolized by large companies.
  3. Content creators are forced to rely on ads; only the big players can win, and they become shameless in their pursuit of money.
  4. The internet urgently needs a foundational framework that incentivizes creativity and protects privacy. While Bitcoin is not the answer, blockchain has potential.

Aaron Sedley: Change aversion: why users hate what you launched (and what to do about it)

· One min read

What is change aversion?

By and large, anytime you change what people regularly use in a product, they will always throw an uproar. This happens to almost every release of products like Gmail, YouTube, iPhone, etc.

How to avoid or mitigate change aversion?

  1. Let users understand, in advance and afterward. Warn them about the significant changes early and communicate why those places changed. Provide transition instructions afterward.
  2. Let users switch. Don’t shut the door and leave them alone in the helplessness.
  3. Let users give feedbacks and follow through.

Change Aversion isn’t an Excuse

The product changes may turn out to be good or bad ones.

change aversion patterns

Differences and Similarities in Eastern and Western Workplace Cultures

· 2 min read

Here are some immature observations. I have never worked in China, so I filled in the section for Chinese people based on what I heard and saw in school.

Differences

What Americans ValueWhat Chinese People Value
Persuasiveness
Public speaking is the foundation of a democratic society
Actions speak louder than words
A gentleman is cautious in speech but quick in action
Being emotional is shameful/unprofessional
Hypocrisy/professionalism
Being genuine
Losing face
Meetings are for making decisionsMeetings are for finalizing decisions
Preference for diamondsPreference for jade
Confidence
Even if it’s not possible, say it is
I am better than others
Humility
Even if it’s possible, say it’s not
Others are better than me
Independent thinking
Challenging authority
Team spirit
Obedience and execution

Similarities

Both Americans and Chinese value:

  • Business acumen
  • Vision and strategic decision-making ability
  • Unity is strength (The Chinese people I have worked with in the past were very united, although many have biases against this)
  • People are more important than tasks; relationships determine outcomes
  • Flexibility in responding to VUCA (Volatility, Uncertainty, Complexity, Ambiguity)

A Closer Look at iOS Architecture Patterns

· 3 min read

Why Should We Care About Architecture?

The answer is: to reduce the human resources spent on each feature.

Mobile developers evaluate the quality of an architecture on three levels:

  1. Whether the responsibilities of different features are evenly distributed
  2. Whether it is easy to test
  3. Whether it is easy to use and maintain
Responsibility DistributionTestabilityUsability
Tight Coupling MVC
Cocoa MVC❌ V and C are coupled✅⭐
MVP✅ Independent view lifecycleAverage: more code
MVVMAverage: View has a dependency on UIKitAverage
VIPER✅⭐️✅⭐️

Tight Coupling MVC

Traditional MVC

For example, in a multi-page web application, when you click a link to navigate to another page, the entire page reloads. The problem with this architecture is that the View is tightly coupled with the Controller and Model.

Cocoa MVC

Cocoa MVC is the architecture recommended by Apple for iOS developers. Theoretically, this architecture allows the Controller to decouple the Model from the View.

Cocoa MVC

However, in practice, Cocoa MVC encourages the use of massive view controllers, ultimately leading to the view controller handling all operations.

Realistic Cocoa MVC

Although testing such tightly coupled massive view controllers is quite difficult, Cocoa MVC performs the best in terms of development speed among the existing options.

MVP

In MVP, the Presenter has no relationship with the lifecycle of the view controller, allowing the view to be easily replaced. We can think of UIViewController as the View.

Variant of MVC

There is another type of MVP: MVP with data binding. As shown in the figure, the View is tightly coupled with the Model and Controller.

MVP

MVVM

MVVM is similar to MVP, but MVVM binds the View to the View Model.

MVVM

VIPER

Unlike the three-layer structure of MV(X), VIPER has a five-layer structure (VIPER View, Interactor, Presenter, Entity, and Routing). This structure allows for good responsibility distribution but has poorer maintainability.

VIPER

Compared to MV(X), VIPER has the following differences:

  1. The logic processing of the Model is transferred to the Interactor, so Entities have no logic and are purely data storage structures.
  2. ==UI-related business logic is handled in the Presenter, while data modification functions are handled in the Interactor==.
  3. VIPER introduces a routing module, Router, to implement inter-module navigation.

How to Stream Video to Mobile Devices Using HTTP? HTTP Live Streaming (HLS)

· One min read

Why Is Such a Protocol Needed?

Mobile video playback services using HTTP Live Streaming encounter the following issues:

  1. ==Limited memory and storage on mobile devices==.
  2. Due to unstable network connections and varying bandwidth, there is a need to ==dynamically adjust video quality during transmission==.

Solutions

  1. Server Side: In a typical setup, encoding hardware receives audio and video input, encodes it into H.264 format video and AAC format audio, and then streams it out in MPEG-2 format.
    1. A software multiplexer then splits the raw output stream into a series of short media files (with lengths possibly around 10 seconds in .ts format).
    2. The multiplexer also maintains an index file (.m3u8 format) that contains a list of all media files.
    3. The generated media files and index file are published on a web server.
  2. Client Side: The client reads the index, sequentially requests the necessary media files from the server, and smoothly plays the content of each short media file.

Architecture

HLS Architecture

Designing Facebook's Photo Storage System

· 2 min read

Why Does Facebook Handle Its Own Photo Storage?

  • Petabyte-scale volume of blob data
  • Traditional NFS-based designs (where each image is stored as a file) face metadata bottlenecks: massive metadata severely limits metadata hit rates.
    • Here are the details:

For photo applications, most metadata, such as image permissions, is useless, wasting storage space. However, the larger overhead is that the metadata of the file must be read from disk into memory to locate the file itself. While this is negligible for small-scale storage, when multiplied by billions of photos and several petabytes of data, accessing metadata becomes a throughput bottleneck.

Solution

By aggregating hundreds of thousands of images into a single Haystack storage file, the metadata burden is eliminated.

Structure

Facebook Photo Storage Architecture

Data Layout

Index file (for quick memory loading) + Haystack storage file containing many images.

Index file layout

index file layout 1

index file layout 2

Storage file

haystack store file

CRUD Operations

  • Create: Write to the storage file, then ==asynchronously== write to the index file, as indexing is not a critical step.
  • Delete: Perform soft deletes by marking the deleted bits in a flag field. Execute hard deletes through compacting operations.
  • Update: During updates, only append (append-only); if a duplicate key is encountered, the application can choose to update and read the key with the maximum offset.
  • Read: Read operations (offset, key, backup key, cookie, and data size)

Use Cases

Upload

Photo Storage Upload

Download

Photo Storage Download

Learning to Be Trusted — It Only Takes 72 Minutes to Incite Murder

· 6 min read

Traditional wisdom tells us that losing trust happens quickly, while gaining trust takes time. However, this is not entirely true. The renowned British mentalist Derren Brown, in his reality show "Derren Brown: The Push," utilized various psychological techniques to lead a kind-hearted ordinary person to commit a horrific murder by pushing an elderly man off a building—all within 72 minutes.

The protagonist of the story is Chris, a mild-mannered, sunny young man. Although he appears to be just an average person, he was meticulously selected for the experiment due to his strong tendency to conform to social pressures. Chris was unaware of the experiment's true purpose, as the production team informed him that he had not been selected, which allowed him to let his guard down. The team arranged for someone to impersonate a high-ranking executive from a charitable organization to contact Chris's company about a collaboration and invited him to help organize an event. To quickly establish authority, the event featured numerous celebrity endorsements, and Chris was tasked with serving drinks, carrying bags, and handling clothing to train his sense of obedience.

Then the incident began. With only the executive and Chris present, a wealthy old man suddenly "died." The executive persuaded Chris to consider the bigger picture and asked him to help hide the body, which he did. Later, the event host mistakenly thought Chris was the wealthy old man and called him to the stage to speak, and he complied. The executive instructed Chris to move the body, and he followed suit. Eventually, the old man's wife mentioned that he had a condition that made him appear dead during episodes, which relieved both the executive and Chris. Unexpectedly, the production team arranged for the old man to "wake up" and, using a recording device from his pocket, he "learned" everything that had happened since his "death," threatening to expose the two and refusing to donate a penny to the charity. In the end, fearing for his job and potential imprisonment, the executive urged Chris to eliminate the old man by pushing him off the edge of the platform. However, he… did not comply. In fact, Chris was the only one of the four participants who did not obey the "murder" command.

The fact that the other three "murderers" complied so quickly illustrates how rapidly trust can be established, allowing individuals to follow orders to the extent of committing murder.

So how is trust built? Psychologists have long had the answer: ==Trust equals competence plus approachability==. For instance, in the aforementioned murder-inciting reality show, the executive presented himself as sophisticated and high-status, and the entire charity event was backed by social elites.

Here, ==“competence” does not require someone to genuinely be competent; it merely requires them to appear competent==. For example, using a lot of jargon when speaking can make one sound like an expert. A more superficial method is appearance—driving a luxury car and wearing cufflinks can help people remember you. The key is appropriateness; don’t wear a suit and tie to a garage to fix someone’s car, and don’t show up in flip-flops and shorts to give a speech at a charity gala.

Another effective way to enhance perceived competence is through consistency between words and actions; no one will trust a hypocrite. If I lived in the world of "The Smiling, Proud Wanderer," I would certainly trust the honest rogue Tian Boguang, rather than the pretentious hypocrite Yue Buqun.

Competence, or "credibility," can be mutually reinforced between individuals and organizations. Both people and organizations can increase their credibility by joining exclusive associations, and when high-credibility individuals and organizations join, the association's credibility rises even higher. I feel that there is an old Chinese saying, "A flower-laden sedan chair is carried by people," which may express this very idea. The most direct product of mutual credibility is money; the easier it is to establish credibility through interaction, the more people trust each other, leading to increased transactions and a higher overall economic level in society.

Many national leaders give an impression of being "competent," yet are quite cold. To enhance public trust, each U.S. president adopts a dog. For instance, Obama had never owned a dog before moving into the White House, and his daughter Malia was even allergic to dogs, but he felt compelled to get one. After all, few things can make people feel as approachable as a furry, tail-wagging, wide-eyed dog.

This is the power of "approachability." A professor at Harvard conducted an experiment and found that on rainy days, when borrowing a phone from a stranger at a bus stop, simply saying, "I apologize for the rain," before making the call increased the likelihood of success fourfold. Research has shown that ==no matter how exaggerated the apology may be, this method consistently promotes cooperation in real life==.

In fact, ==to convey approachability, the way you speak is often more important than the content of your speech, and body language is more significant than verbal language==. Sitting closer, leaning forward, shaking hands, patting shoulders, and touching elbows can all powerfully express the intention to cooperate. ==When it comes to trust, face-to-face communication is extremely important==. I have a classmate from Yale who, after receiving an offer from Uber, directly negotiated his salary with his boss and ended up discussing it all the way to the director level, securing several thousand shares of stock!

Beyond these two dimensions, what other methods can enhance trust? The answer is exposing minor weaknesses. For example, "accidentally" dropping a pen, "accidentally" telling a bad joke, or "accidentally" spilling coffee.

Competent individuals can consciously make small mistakes or reveal minor secrets to appear more relatable. In a previous MBA program at Columbia University, there was an executive student who intentionally included typos in her emails to seem more approachable, and her relationships with colleagues genuinely improved. This explains why Japanese employees enjoy getting drunk together after work and then singing karaoke off-key. The worse you perform, the deeper your bond with friends becomes.

Of course, revealing weaknesses must be done carefully. ==Before exposing weaknesses, people must recognize that you are genuinely competent==. Additionally, ==the weaknesses must be trivial==. A surgeon with shaky hands or a quarterback with butterfingers are not minor weaknesses; they are serious flaws.

In summary, ==Trust = Competence + Approachability + Exposure of Minor Weaknesses==. To be trusted, you must first be worthy of trust; you need to be competent. Not only must you be competent, but you also need to establish a connection with the other party, which requires you to appear approachable. Once trust is established, if you appear overly competent or too perfect, it can create a sense of distance and threat, so you must also expose minor weaknesses to bridge the gap with others.

iOS Architecture Patterns Revisited

· 2 min read

Why bother with architecture?

Answer: for reducing human resources costs per feature.

Mobile developers evaluate the architecture in three dimensions.

  1. Balanced distribution of responsibilities among feature actors.
  2. Testability
  3. Ease of use and maintainability
Distribution of ResponsibilityTestabilityEase of Use
Tight-coupling MVC
Cocoa MVC❌ VC are coupled✅⭐
MVP✅ Separated View LifecycleFair: more code
MVVMFair: because of View's UIKit dependantFair
VIPER✅⭐️✅⭐️

Tight-coupling MVC

Traditional MVC

For example, in a multi-page web application, page completely reloaded once you press on the link to navigate somewhere else. The problem is that the View is tightly coupled with both Controller and Model.

Cocoa MVC

Apple’s MVC, in theory, decouples View from Model via Controller.

Cocoa MVC

Apple’s MVC in reality encourages ==massive view controllers==. And the view controller ends up doing everything.

Realistic Cocoa MVC

It is hard to test coupled massive view controllers. However, Cocoa MVC is the best architectural pattern regarding the speed of the development.

MVP

In an MVP, Presenter has nothing to do with the life cycle of the view controller, and the View can be mocked easily. We can say the UIViewController is actually the View.

MVC Variant

There is another kind of MVP: the one with data bindings. And as you can see, there is tight coupling between View and the other two.

MVP

MVVM

It is similar to MVP but binding is between View and View Model.

MVVM

VIPER

There are five layers (VIPER View, Interactor, Presenter, Entity, and Routing) instead of three when compared to MV(X). This distributes responsibilities well but the maintainability is bad.

VIPER

When compared to MV(X), VIPER

  1. Model logic is shifted to Interactor and Entities are left as dumb data structures.
  2. ==UI related business logic is placed into Presenter, while the data altering capabilities are placed into Interactor==.
  3. It introduces Router for the navigation responsibility.

Key value cache

· 3 min read

KV cache is like a giant hash map and used to reduce the latency of data access, typically by

  1. Putting data from slow and cheap media to fast and expensive ones.
  2. Indexing from tree-based data structures of O(log n) to hash-based ones of O(1) to read and write

There are various cache policies like read-through/write-through(or write-back), and cache-aside. By and large, Internet services have a read to write ratio of 100:1 to 1000:1, so we usually optimize for read.

In distributed systems, we choose those policies according to the business requirements and contexts, under the guidance of CAP theorem.

Regular Patterns

  • Read
    • Read-through: the clients read data from the database via the cache layer. The cache returns when the read hits the cache; otherwise, it fetches data from the database, caches it, and then return the vale.
  • Write
    • Write-through: clients write to the cache and the cache updates the database. The cache returns when it finishes the database write.
    • Write-behind / write-back: clients write to the cache, and the cache returns immediately. Behind the cache write, the cache asynchronously writes to the database.
    • Write-around: clients write to the database directly, around the cache.

Cache-aside pattern

When a cache does not support native read-through and write-through operations, and the resource demand is unpredictable, we use this cache-aside pattern.

==There are still chances for dirty cache in this pattern.== It happens when these two cases are met in a racing condition:

  1. read database and update cache
  2. update database and delete cache

Where to put the cache?

  • client-side
  • distinct layer
  • server-side

What if data volume reaches the cache capacity? Use cache replacement policies

  • LRU(Least Recently Used): check time, and evict the most recently used entries and keep the most recently used ones.
  • LFU(Least Frequently Used): check frequency, and evict the most frequently used entries and keep the most frequently used ones.
  • ARC(Adaptive replacement cache): it has a better performance than LRU. It is achieved by keeping both the most frequently and frequently used entries, as well as a history for eviction. (Keeping MRU+MFU+eviction history.)

Who are the King of the cache usage?

Facebook TAO