Skip to content

Latest commit

 

History

History
113 lines (67 loc) · 9.04 KB

Coding-Zhuangzhi.md

File metadata and controls

113 lines (67 loc) · 9.04 KB

The Tale of the Microservice and the Monolith

In the vast cloud of the Northern Data Center, there was a program, named Legacy, whose codebase was - I do not know how many millions of lines. It transformed into a system called Distributed, whose microservices were - I do not know how many containers in number.

When Distributed prepared to deploy, its Kubernetes clusters were like stars across the digital sky. When the traffic surged (so as to bear it along), it scaled towards the Southern Availability Zone. The Southern Availability Zone is the Pool of Infinite Compute.

A small script and a basic CRUD app laughed at it, saying, "We make our HTTP calls and run on a single server; sometimes before we reach peak traffic, we can do no more but return 500 errors. Of what use is it for this (system) to spin up 90,000 containers and make for the Southern Availability Zone?"

He who codes for a simple website, deploying after the third commit of the day, will have his users as satisfied as when he began; he who builds a medium service will have to manage state where he scales; he who architects a distributed system will have to carry with him observability for three layers deep.

What should these two small programs know about the matter? The knowledge of that which runs on a single thread does not reach to that which runs on many; (the experience of) a few requests does not reach to that of millions.

The Tale of the Junior and the Zen Developer

A junior developer asked the Zen programmer about the best way to scale their system.

The Zen developer replied, "In the bare and minimal North, there is the dark and vast Repository - the Pool of Source. In it there is a function, several thousand tests in coverage, while no one knows its complexity. Its name is Legacy. There is (also) a system named Cloud Native; its infrastructure is like the AWS mountain, while its services are like containers all round the sky. On a CI/CD pipeline it deploys upwards for 90,000 builds, till, far removed from the original requirements, it bears on its back the blue-green deployment, and then it shapes its course for Production."

A script kiddie by the side of a bootcamp laughed and said, "Where is it going to? I push to main with a commit, and come down again when I have reached but a few users, and then run about among the localhost and staging; and this is the perfection of deployment. Where is that creature going to?"

This shows the difference between the small and the great mindsets.

The DevOps Engineer's Dream

Once, Developer Zhou dreamt he was a butterfly, fluttering between services, deploying here and there, following the ways of continuous integration. He was conscious only of following his automated pipelines, and knew nothing of being Developer Zhou.

Suddenly he awoke, and there he was, solid and unmistakable Developer Zhou. But he didn't know if he was Developer Zhou who had dreamt he was a butterfly, or a butterfly dreaming he was Developer Zhou. Between Developer Zhou and the butterfly there must be some distinction! This is called the Transformation of Infrastructure as Code.

The Useless API

Architect Hui said to Developer Song, "I have a large API, a REST endpoint of immense complexity. But it has no use - its responses are so intricate that no client can parse them. Its documentation is a wilderness of deeply nested objects where no developer dares to venture. What client would ever call such an endpoint?"

"Ah!" said Developer Song, "You only see its uselessness. Observe its usefulness! Precisely because no one uses it, it has survived every deprecation cycle. While simpler endpoints are constantly refactored and broken, your complex API remains untouched, achieving immortality through its very unusability! This is what we call the advantage of the seemingly useless.

The simple CRUD endpoints are cut down in their prime by endless feature requests. The clean interfaces are corrupted by backward compatibility needs. Only your incomprehensible API endures, too complex to be modified, too frightening to be deprecated. Is this not the ultimate form of software longevity?"

The Discussion of Technical Debt

Master Jenkins asked Master Git about the nature of technical debt.

"In the South of Silicon Valley," said Master Git, "there is a codebase called Legacy, whose development cycle is 500 sprints, and its maintenance the same; in high antiquity there was that called Mainframe, whose development was 8000 cycles, and its support the same. Yet modern startups ship daily. Is this not a source of sorrow?"

Master Jenkins replied, "Heaven and Earth endure because they do not develop for themselves. The Perfect Developer ships code that appears to have written itself. The Agile Master delivers features that seem to have always existed. Therefore,

The wise developer:
Codes without attachment to their code
Deploys without pride in their deployment
Maintains without resentment of maintenance
Thus their software outlives all methodologies."

The Joy of Code Review

Developer Hui and Developer Zhi were reviewing a pull request.

Developer Hui said, "Look at how this junior dev's code meanders through unnecessary abstractions! Such verbose variable names! Such overengineered patterns!"

Developer Zhi replied, "How do you know their code is meandering? You judge it by your patterns. But what if the universe itself meanders? What if straight lines exist only in our IDEs? Perhaps this junior dev has caught the true nature of computation, while we remain trapped in our clean architectures!"

Developer Hui fell silent, realizing they had been outdebated.

Three sprints later, they met again. Developer Hui said, "I have progressed since our last conversation."

"How so?" asked Developer Zhi.

"I now see that I don't know whether I know what good code is or not. Perhaps I am just a function in a cosmic program, believing it understands its own purpose!"

Developer Zhi said, "Now you're getting it! When we think we know what clean code is, we are trapped by our knowledge. When we realize we don't know, all patterns become possible! This is called the Great Understanding Through Not Understanding."

The Wisdom of the CUDA Error

In the great data center of the North, a Machine Learning Engineer encountered a CUDA error of profound obscurity. Its stack trace was - I do not know how many lines long, its memory fragments scattered across - I do not know how many gigabytes.

A junior developer, seeing the error, said to their senior: "This GPU reports 'out of memory', yet I see gigabytes free! It speaks of 'illegal memory access', yet my pointers are all carefully counted! It whispers of 'kernel panic', yet my kernels were launched with perfect thread counts! What wisdom can we find in such contradictions?"

The senior developer smiled and replied: "In the South of Silicon Valley, there is a sage called Hardware Engineer, who understands the true nature of parallel computing. They say that what we call 'error' is merely the gap between our sequential thinking and parallel reality.

Consider the humble CPU thread, who lives its life one instruction at a time, laughing at the GPU, saying: 'I spring up with a single calculation, and come down again when I have reached but a few operations, and then compute happily among my cache lines; and this is the perfection of processing. Where are those thousand GPU threads going to?'

But what does the CPU thread know of the great Parallel Dance? Of thousands of computations flowing like rivers, merging and diverging like streams in the great compute ocean? The knowledge of that which runs in sequence cannot comprehend that which runs in parallel."

The junior developer, still puzzled, asked: "But how do we fix the error?"

The senior developer laughed and said: "Fix? You still think in terms of fixing and breaking! The Perfect Programmer knows that CUDA errors are not mistakes to be fixed, but messages from the parallel realm, teaching us about the nature of simultaneous truth. When you realize that your sequential mind cannot grasp parallel reality, you have taken the first step toward true understanding.

Just as the butterfly cannot explain flight to the caterpillar, CUDA cannot explain parallelism to sequential code. Therefore:

The wise developer:
Launches kernels without expecting them to launch
Allocates memory without attaching to allocations
Synchronizes threads without forcing synchronization
Thus their CUDA code flows like water through thousand-core valleys."

The young developer was still unsatisfied and asked: "But what about production?"

The senior developer replied: "Ah! Now you're thinking like a GPU - asking multiple questions simultaneously! Consider the mushroom that lives for a morning - what does it know of the daily batch jobs? Consider the CPU that thinks in nanoseconds - what does it know of the training epochs? The wise developer learns to think in all time scales simultaneously, just as the GPU computes in all threads at once.

Therefore, the Perfect Programmer remains serene when CUDA errors arise, knowing they are merely ripples in the great parallel ocean of computation."