Skip to content

System Design Basics in PHP

Glossary

163 terms from System Design Basics in PHP, in plain words, each with the chapter that teaches it.

A

ACID
Four promises a database makes about transactions: atomicity (all or nothing), consistency (rules still hold), isolation (concurrent transactions don't see each other's half-done work) and durability (committed data survives a crash).
Alert
An automatic message to a person when a metric crosses a set line, such as an error rate above 1% for 5 minutes.
API (Application Programming Interface)
A set of requests a program accepts from other programs, such as api.kettleandcrane.com's product and order endpoints.
API key
A long secret string a caller sends in a header, such as `Authorization: Bearer <token>`, to prove who it is.
Asynchronous work
Work done a moment later by something else, so the customer's request doesn't wait for it. At Kettle & Crane, the confirmation email is asynchronous while saving the order is synchronous.
At-least-once delivery
A queue promise that every message arrives, but sometimes twice, for example when a worker finishes the job and crashes before telling the broker.
Atomic
An operation that is one step and can't be split, so nothing can happen between the check and the change. A single `UPDATE ... WHERE qty >= ?` is atomic.
Authentication
Proving who the caller is, usually with a token or API key.
Authorization
Deciding what a known caller may do, such as letting customers read their own orders but only staff read everyone's.
Auto-increment ID
A number the database hands out in order (1, 2, 3...) for each new row. The shortener turns it into a short code.
Autoscaling
Automatically adding servers when load rises and removing them when it falls, by a rule such as keeping average CPU under 60%.
Availability
The share of time a system answers, as a percentage such as 99.9%.

B

Back pressure
Pushing back on producers, for example by refusing new messages, when a queue is full so it doesn't grow until memory runs out.
Back-of-the-envelope estimate
A rough calculation aiming for the right order of magnitude, such as 2, 200 or 20,000 requests a second, so you don't build something far too big or small.
Backups
Copies of the data kept elsewhere so it can be restored after a disaster. Test them by actually restoring one.
Base62
Writing a number with 62 symbols (0-9, a-z, A-Z) instead of 10, so short links stay short. Six symbols cover about 56.8 billion links.
Batching
Grouping many writes into one, such as one commit after many inserts, so the slow wait for disk happens once.
beginTransaction / commit / rollBack
PDO methods that start a transaction, save all its changes, or undo them all. They make a group of statements succeed or fail together.
Broker
The program that stores a message queue between producers and consumers, such as RabbitMQ or Amazon SQS.

C

Cache
A small, fast store of copies of data that is slow to get, such as a product page read thousands of times between price changes.
Cache hit / miss
A hit is when the data is found in the cache. A miss is when it isn't, so you fetch it from the slow source. The hit ratio is hits divided by all lookups.
Cache invalidation
Removing or updating a cached copy when the data changes, such as deleting a product's key right after Jo changes its price.
Cache stampede
What happens when a hot cache key expires and every request misses at once, flooding the database. Letting one request reload it while others wait avoids it.
Cache-aside
The usual caching pattern: the app checks the cache first, and on a miss reads the database and stores the result in the cache.
Cache-Control header
An HTTP header telling browsers and CDNs how long to keep a file, for example `max-age=86400` for one day. It is a TTL set by HTTP.
CAP theorem
During a network partition a system must choose consistency (refuse rather than be wrong) or availability (answer, maybe with stale data). When the network is fine, you get both.
CDN (content delivery network)
Servers in many cities that hold copies of files such as product photos, so customers get them from nearby instead of from Portland.
Celebrity problem
A feed problem where one very popular source has so many followers that fanning out on write means huge numbers of writes and late delivery. Hybrid fan-out is the usual fix.
Circuit breaker
A guard that notices repeated failures calling a service and stops calling it for a while. It is closed while calls go through, open when refusing, and half-open when it allows a trial call.
Client / server
A client is a program that asks for something, like a browser or `client.php`. A server is the program that answers.
Component
One part of a system, such as a web server, database, cache or queue.
Composer
PHP's package manager, used to install and update third-party libraries a project depends on. Tools such as PHPUnit are distributed as Composer packages.
Consensus
Getting several servers to agree on something, such as which replica becomes the new primary. It is covered in the next book.
Consistency
Whether all readers see the latest data. Strong and eventual consistency are the two ends of this choice.
Consistent hashing
A sharding method that moves only a small share of keys when shards are added or removed, instead of most keys as with `%`.
Content-Type
An HTTP header saying what kind of data the body holds, such as `application/json`.
crc32
A PHP built-in checksum function that turns a string into a large whole number. It always gives the same number for the same key, so it works as a stable hash for sharding.
Cross-shard query
A question that doesn't include the shard key, so it must ask every shard and combine the answers, like "best sellers this week".

D

Dead-letter queue
A separate queue where messages go after failing too many times, so a person such as Priya can look at them instead of retrying forever.
Denormalization
Storing a copy of data in the shape a page needs, even though it repeats data held elsewhere, to make reads cheap. An example is the `best_sellers` table.
Design document
A short shared description of what you'll build and why, which a team reviews before anyone writes code.
DNS (Domain Name System)
The internet's phone book. It turns a name like shop.kettleandcrane.com into an IP address.
Document store
A NoSQL database that stores JSON-like documents, handy for products with varied fields. MongoDB is an example.
Downtime
The time a system is not answering. Availability targets are often expressed as allowed downtime per year.
Durability
Saved data is never lost, even after a crash. Once an order is confirmed, it stays.

E

Edge location
One of a CDN's servers in a city near users, where copies of files are kept.
Endpoint
One method and path pair that an API accepts, such as `GET /v1/products`.
Error rate
The share of requests that fail, a common metric to watch and alert on.
Eventual consistency
Reads may be briefly out of date, but once writes stop every copy catches up, as with read replicas.
Eviction
Throwing entries out of a full cache to make room. LRU is a common rule for choosing which to remove.
EXPLAIN QUERY PLAN
A SQLite prefix that makes it describe how it would run a query, without running it. It says `SCAN` for a full read or `SEARCH ... USING INDEX` when an index helps.
Exponential backoff
Doubling the wait after each failed retry (0.1 s, 0.2 s, 0.4 s...) to give a struggling server room to recover.

F

Failover
Switching to a standby when the main part fails, such as promoting a replica to primary or a spare load balancer taking over an address.
Fake clock
A clock function a test controls by hand, so a cache's expiry can be tested without waiting 60 real seconds.
Fallback
A simpler answer shown when a part fails, such as a cached "Popular this week" list when recommendations are down.
Fan-out
Copying one post or message to many readers, such as a café's post to each follower's feed.
Fan-out on write / read
On write, a post is pushed into every follower's feed when it's posted: posting is slow and reading is fast. On read, posts are stored once and gathered when someone opens the feed: posting is cheap and reading is slow.
Feed
A list of posts from the sources you follow, newest first, like customers following cafés in the Kettle & Crane app.
file_get_contents
A PHP function that reads a file or URL into a string. It can call an HTTP API, with a stream context to set options such as a timeout or to return the body of error responses.
Functional requirement
What the system does, such as "customers can check out" or "Priya can look up an order by its ID".

G

Graceful degradation
Offering less instead of nothing when a part fails, such as showing a cached list or letting emails wait on the queue.

H

Hash sharding
Picking a shard by turning the key into a number with a stable hash and taking the remainder after dividing by the shard count.
Header
A `Name: value` line in an HTTP request or response that carries extra information, such as `Content-Type` or `Idempotency-Key`.
Health check
A regular test, such as `GET /v1/health`, that a server is answering. A server that fails is marked down and gets no requests until it passes again.
Horizontal scaling
Adding more machines to share the work. It has no ceiling, but the data and traffic must be split between them.
Hot spot
A shard or key that gets far more traffic than the rest, for example the newest shard under date-range sharding or a café with many orders.
hrtime
A PHP function returning a high-resolution clock in nanoseconds that never jumps backward, used to time code and in clocks.
HTTP (Hypertext Transfer Protocol)
The plain-text protocol browsers and servers use: a request (method, path, headers, maybe a body) goes out and a response (status code, headers, body) comes back.
HTTP method
The first word of an HTTP request, saying what to do: `GET` reads, `POST` creates, `PUT` replaces and `DELETE` removes.
HTTP status codes
The number that starts an HTTP response: 2xx means success, 4xx the client's mistake, 5xx a server problem. Common codes: 200 OK, 201 Created, 301 moved for good, 302 moved for now, 400 bad request, 401 not logged in (caller not proven), 403 not allowed (caller known), 404 not found, 409 conflict with current state, 429 too many requests, 500 server error, 503 service unavailable.
HTTPS / TLS
HTTP encrypted with TLS so nobody between the browser and server can read things like card numbers or tokens.
Hybrid fan-out
Fan out on write for ordinary sources, but fetch very popular sources' posts at read time and merge them in.

I

Idempotency key
A unique ID the app sends with a request, in an `Idempotency-Key` header, so the server can recognize a retry and return the first result instead of acting twice.
Idempotent
Doing it twice has the same effect as doing it once. `GET` is idempotent; a plain `POST` that creates an order is not.
Idempotent consumer
A queue worker that records which messages it has handled and skips repeats, so a duplicate message has no extra effect.
Index
A sorted list of one column's values, each pointing at its rows, so the database can jump straight to them instead of scanning. It makes writes slightly slower.
IP address
A number such as 203.0.113.7 that identifies a machine on the internet.

J

Jitter
Randomness added to retry waits so a thousand clients don't all retry at the same instant.
Join
A SQL query that combines rows from several tables at once. It is a main feature of relational databases.
JSON
A text format for data, used for API bodies. PHP's `json_encode` turns an array into JSON and `json_decode` turns it back.

K

Kafka
A popular message broker built around topics, used for event streaming. It is covered in the next book.
Key-value store
A NoSQL database that holds one value per key, like an associative array. It suits sessions and carts, and Redis is an example.

L

Latency
How long one request takes, measured in units like milliseconds.
Latency units
A millisecond (ms) is a thousandth of a second, a microsecond (µs) a millionth and a nanosecond (ns) a billionth. Memory reads take about 100 ns, SSD reads 0.1 ms and a Portland-to-Virginia round trip 70 ms.
Layer 4 / Layer 7
A Layer 4 balancer looks only at addresses and ports and passes bytes on unread, so it's very fast. A Layer 7 balancer reads the HTTP request, so it can route by path and handle HTTPS.
Least connections
A balancing rule that sends each request to the server with the fewest requests still open, which handles requests of uneven cost better than round robin.
Load balancer
A server in front of the app servers that takes every request and passes it to one of them, so customers only see one address.
Logs
Records of events, such as each failed charge. PHP's `error_log()` writes one line to the server log.
LRU (least recently used)
An eviction rule that throws out the entry that hasn't been read or written for the longest time when the cache is full.

M

Memcached
A shared cache server, like Redis, that keeps copies of data in memory for many app servers.
Message queue
Holds messages from producers until consumers take them, so slow work happens later and the customer's reply stays fast.
Metrics
Numbers measured over time, such as requests per second or the error rate.
Microservices
A design that splits a system into many small programs that talk to each other over APIs. It contrasts with a monolith, which is one program that does everything.
Monitoring
Watching what a system is doing, through logs, metrics and alerts, so problems are noticed.
Monolith
One program that does everything. Kettle & Crane's shop is designed as a monolith with a few helpers.

N

Network partition
A network failure in which some servers can't reach others, such as replicas losing contact with the primary.
nginx / HAProxy
Common load balancers that you run yourself.
Nines
A way to describe availability by counting the 9s: 99.9% is "three nines". Each extra nine cuts allowed downtime by ten and costs much more.
Non-functional requirement
How well the system does its job: latency, availability, durability and scalability.
NoSQL
Databases that aren't relational tables, such as key-value, document and wide-column stores. They give up some features for simplicity and very large scale.

O

Object storage
A service that stores any number of files by name, cheaply and durably. Amazon S3 is the best known, and a CDN fetches photos from it.
Order of magnitude
The rough size of a number, such as 2, 200 or 20,000, which matters more in estimates than the exact value.
Outbox
A queue of work to do once an order is safely saved. The order ID is put on it only after the commit.

P

p99 / percentile
The time that 99% of requests beat. It reveals slow requests an average hides, such as an 80 ms average with a 3 second p99.
Pagination
Returning a long list one piece at a time, with a parameter like `?page=2` or `?after=K-1040`.
PDO
PHP's built-in database interface, used here with the SQLite driver. It runs SQL with prepared statements and transactions.
Peak factor
How many times the average load the busiest moment reaches. For the shop's holiday sale hour it's about 10.
php -S
PHP's built-in development web server. It runs one router script file for every request, with request details in `$_SERVER`, and handles one request at a time.
PHPUnit
PHP's most widely used testing framework, installed as a Composer package. It runs automated tests that check code behaves as expected, as a simple hand-written `check()` helper can also do on a small scale.
Polling
Asking again and again whether anything is new, such as a browser checking for chat messages every few seconds. It is simple but slow and wasteful.
Port
A numbered door on a machine that lets one computer run many network services at once. For example, 443 is used for secure web traffic (HTTPS), and a local test server might use 8121.
Precompute
Calculating a heavy result ahead of time, such as the best sellers every 10 minutes, and storing it so each page view is cheap.
Presence
Knowing who is online. The chat design keeps a key like `online:priya` with a short TTL that the app keeps refreshing.
Primary
The database copy that takes every write and passes changes on to the read replicas.
Producer / consumer
The producer is the code that puts messages on a queue, like checkout. The consumer, or worker, takes them off and does the work, like sending the email.
Pub/sub (publish/subscribe)
A pattern where one message published to a topic is delivered as a copy to every subscriber, unlike a queue that gives each message to one consumer.

R

RabbitMQ / Amazon SQS
Common message brokers that store queues on their own server so workers can run elsewhere and messages survive a restart.
Race condition
A bug whose result depends on the timing of two actions, such as two checkouts both reading stock 1 and both selling the last bag.
Range sharding
Giving each shard a range of keys, such as a span of dates. It makes range questions easy but risks a hot spot on the newest shard.
Read replica
A copy of the database that receives the primary's changes and answers reads, so more servers can handle more reads.
Read-heavy / write-heavy
A read-heavy system is read far more often than changed, like the shop at about 100 reads per order. A write-heavy one, like click logging, is the reverse. The ratio shows which side to scale first.
Read-your-writes
A promise that a user always sees their own latest changes, often by reading their data from the primary for a short time after they write.
Redirect
A 301 or 302 response that sends the browser to another URL, given in a `Location` header. 301 means moved for good (browsers may skip your server next time); 302 means moved for now, so every click returns to you and can be counted.
Redis
A popular in-memory key-value store, used as a shared cache server or for sessions and carts.
Redundancy
Having two or more of each critical part so that one failing doesn't stop everything.
Relational database
A database of tables with fixed columns, queried with SQL, where tables can be combined in one query. It suits orders and stock, which must add up.
Replication
Keeping copies of a database on several servers, with the primary taking writes and replicas receiving each change.
Replication lag
The delay before a change on the primary reaches a replica. A read right after a write may show the old value.
Requirement
Something the system must do or be. They are either functional or non-functional.
Resharding
Moving rows to their new shards when you add or remove shards. With `%` most keys move, which is costly while the shop keeps running.
Resource
The thing a REST URL names, written as a noun such as `orders`. The HTTP method says what to do with it.
REST
A common API style where URLs name resources (nouns like `orders`) and HTTP methods say what to do with them.
Retry
Trying a failed call again, worth doing for brief failures. It is safe only for idempotent work, and should use backoff and jitter.
Round robin
Giving requests to servers in turn: app1, app2, app3, then back to app1.
RPS (requests per second)
The key load number. Average RPS is daily requests divided by 86,400, and peak RPS is that times the peak factor.

S

Scalability
Keeping working as the load grows.
Scan
When the database reads every row of a table to answer a query, because no index helps.
Session
What a server knows about one visitor, such as who is logged in and what's in their cart.
Shard key
The column that decides which shard a row lives on, such as `customer_id` for orders so one customer's history stays on one shard.
Sharding
Splitting one table's rows across several databases, each piece called a shard. It scales writes but adds costs, so shard only when you must.
Short code
The few symbols after the slash in a short link, such as `abc12` in `go.kettleandcrane.com/abc12`.
SLO (service level objective)
A team's target for a service, such as "checkout is available 99.9% of the time".
SplQueue
PHP's built-in first-in, first-out queue, with `enqueue` to add at the back, `dequeue` to take from the front and `isEmpty` to check.
SPOF (single point of failure)
One part whose failure stops everything, such as a single database. The cure is redundancy.
Stable hash
A hash that gives the same number for the same key on every machine and every run, so customers don't move shards after a restart.
Stale
Cached or replicated data that no longer matches the source of truth.
Stateless server
A server that keeps no session data in its own memory, but in a database or cache, so any server can answer any request.
Sticky session
A load balancer sending one user to the same server every time because that server holds their cart in memory. If it dies, the cart is lost.
Strong consistency
Every read sees the latest write, as when you read from the primary.
Synchronous work
Work the reply waits for, such as saving the order before telling the customer it worked.
System design
Deciding the parts of a system and how they talk to each other, before or while you build it.

T

TCP
The connection protocol that delivers bytes in order and resends lost ones. HTTP runs over it.
Timeout
The longest you will wait for a reply to a network call. Without one, a hung server can tie up every worker.
Transaction
A group of database changes saved all together or not at all. If something fails, everything is rolled back.
TTL (time to live)
How many seconds a cached entry stays valid. After that it expires, so the next lookup misses and fetches a fresh copy.

U

URL shortener
A service that turns long links into short ones like `go.kettleandcrane.com/abc12` and redirects visitors to the long URL.

V

Versioning
Putting a version such as `/v1/` in API paths so a `/v2/` can appear while old apps keep working.
Vertical scaling
Moving to a bigger machine. It's simple, but there's a largest machine you can buy.

W

WebSocket
A connection that starts as an HTTP request and then stays open, so either side can send a message at any time. It suits chat.
Weighted round robin
Round robin where bigger servers appear more often in the rotation and so get more requests.
Whiteboard sketch
A first drawing of a design: boxes for components and arrows for the messages between them. A wrong box costs an eraser; a wrong server costs months.
Wide-column store
A NoSQL database with huge tables spread over many machines, suited to billions of events. Cassandra is an example.
Write-through cache
A cache that is written together with the database at the same time, instead of being deleted on change.