SQL vs NoSQL: Doğru Database Seçimi
Veritabanı seçimi, uygulamanızın performansını doğrudan etkiler.
SQL (İlişkisel)
Popüler Seçenekler
- PostgreSQL
- MySQL
- SQL Server
Ne Zaman Kullanılır?
- ✅ ACID compliance gerekli
- ✅ Complex queries
- ✅ Structured data
- ✅ Relationships önemli
Örnek (PostgreSQL)
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
total DECIMAL(10,2)
);
-- Join query
SELECT u.email, COUNT(o.id) as order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
GROUP BY u.email;
NoSQL
Document Store (MongoDB)
// Flexible schema
{
_id: ObjectId("..."),
email: "user@example.com",
profile: {
name: "John",
age: 30,
hobbies: ["coding", "gaming"]
},
orders: [
{ product: "Laptop", price: 1000 },
{ product: "Mouse", price: 50 }
]
}
Key-Value (Redis)
// Cache örneği
await redis.set('user:123', JSON.stringify(user), 'EX', 3600);
const cached = await redis.get('user:123');
Column Family (Cassandra)
Yüksek write throughput için ideal.
Karşılaştırma
| Özellik | SQL | NoSQL |
|---|---|---|
| Schema | Fixed | Flexible |
| Scale | Vertical | Horizontal |
| ACID | Full | Eventual |
| Queries | Complex | Simple |
Hybrid Yaklaşım
Modern uygulamalar genelde her ikisini kullanır:
PostgreSQL → Transactional data
MongoDB → User profiles, logs
Redis → Caching, sessions
Projenize göre doğru kombinasyonu seçin!