Sabitlenmiş Tweet
Phoenix.dev
1.6K posts

Phoenix.dev
@0xphxdev
Senior Full-Stack Engineer AI tools • Coding tips • Dev workflows Build faster. Save hours 🚀
🌍Internet, ~/root/h Katılım Aralık 2020
1K Takip Edilen1.2K Takipçiler

THIS QUERY RETURNS DUPLICATES.
SELECT DISTINCT user_id
FROM orders
ORDER BY created_at;
Why?
Because DISTINCT only applies to the columns you select.
You're selecting:
user_id
But ordering by:
created_at
Now the database has a problem:
Which created_at should it use for each unique user_id?
A user can have multiple orders.
Which timestamp wins?
Some databases reject this query completely.
Others return results that look random enough to ruin your afternoon.
What you probably wanted was:
SELECT DISTINCT ON (user_id)
user_id,
created_at
FROM orders
ORDER BY user_id, created_at DESC;
That gives you:
"latest order per user"
SQL gets weird fast once you combine:
- DISTINCT
- ORDER BY
- GROUP BY
And ORMs make it worse because now the broken query is hiding behind:
.distinct().order_by()
...which somehow passed code review.
English

@0xphxdev Nice share, good compiled information about sql query.
English

What will this return?
SELECT COUNT(NULL), COUNT(1), COUNT(*);
Most developers get at least one of these wrong.
Output:
0 | total_rows | total_rows
Why?
COUNT(NULL)
→ counts non-null values
→ NULL is always NULL
→ result: 0
COUNT(1)
→ counts every row because 1 is never NULL
→ result: total row count
COUNT(*)
→ also counts every row
→ result: total row count
So this:
COUNT(1)
and this:
COUNT(*)
are effectively the same in modern databases.
The real trap is this:
COUNT(column_name)
That only counts rows where the column is NOT NULL.
I've seen analytics dashboards quietly undercount users for months because someone wrote:
COUNT(email)
instead of:
COUNT(*)
NULLs don't throw errors.
They just lie quietly.
English

People think motivation comes first.
It doesn't.
You start learning because you're excited.
You continue learning because you're frustrated.
And eventually you keep learning because you've seen what happens when you stop.
The best developers I know aren't motivated every day.
They're just deeply allergic to staying stuck.
That's the real fuel behind most late-night debugging sessions.
Not passion.
Pain.
English

Your microservices architecture has 40 services.
One user request touches 28 of them.
Are you happy with this design?
Or did you accidentally reinvent a distributed monolith with extra network latency?
Every service call adds:
- retries
- timeouts
- tracing noise
- deployment coordination
- another place for auth to break at 2am
I've seen "microservices" where a single feature needed:
Kafka → API Gateway → Auth → User → Billing → Notification → Analytics → 11 more services nobody wanted to own.
The diagrams looked incredible.
The p99 latency did not.
Most teams don't need microservices.
They need better module boundaries inside a monolith and one database query that isn't committing war crimes.
The hard part isn't splitting services.
It's reducing coupling after you split them.
English

@0xphxdev COUNT(NULL)=0 (NULL never counts); COUNT(1)=COUNT(*)=total rows
but COUNT(column) only counts non‑NULLs.
English

@anupamrjp Hi, I’m passionate about backend engineering, system design, and AI. Let’s connect and grow together.
English

@shinemeriz Backend & system design engineer building scalable APIs, SaaS, and production-ready systems.
Let’s connect.
English

@CodeEdison Typescript, because it's force me write structure code
English

@Gooddlovee Hi, I’m passionate about backend engineering, system design, and AI. Let’s connect and grow together.
English

@anupamrjp Backend & system design engineer building scalable APIs, SaaS, and production-ready systems.
Let’s connect.
English
















