Firebase, Google'ın sunduğu kapsamlı bir Backend-as-a-Service (BaaS) platformudur. Mobil ve web uygulamaları için veritabanı, kimlik doğrulama, hosting, analytics ve daha fazlasını tek bir platformda sunar. Özellikle startup'lar ve MVP'ler için hızlı geliştirme imkanı sağlar.
Firebase Servisleri
Build (Geliştirme)
- Cloud Firestore: NoSQL, real-time veritabanı
- Realtime Database: JSON tabanlı gerçek zamanlı DB
- Authentication: Email, telefon, sosyal medya login
- Cloud Storage: Dosya depolama (resim, video)
- Cloud Functions: Serverless backend fonksiyonları
- Hosting: Statik ve dinamik web hosting
Release & Monitor
- Crashlytics: Gerçek zamanlı crash raporlama
- Performance Monitoring: Uygulama performans takibi
- Test Lab: Fiziksel cihazlarda otomatik test
- App Distribution: Beta test dağıtımı
Engage (Etkileşim)
- Analytics: Kullanıcı davranış analizi
- Cloud Messaging (FCM): Push notifications
- Remote Config: Uygulama ayarlarını uzaktan değiştirme
- A/B Testing: Özellik testleri
- Dynamic Links: Deep linking
Firestore vs Realtime Database
| Özellik | Firestore | Realtime DB |
|---|---|---|
| Veri Modeli | Document-Collection | JSON tree |
| Sorgulama | Gelişmiş, compound queries | Sınırlı |
| Ölçekleme | Otomatik | Sharding gerekir |
| Offline | Tam destek | Sınırlı |
| Fiyat | İşlem başına | Bant genişliği |
Firebase Authentication Örneği
// Flutter örneği
import 'package:firebase_auth/firebase_auth.dart';
// Email ile kayıt
Future<UserCredential> signUp(String email, String password) async {
return await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: email,
password: password,
);
}
// Google Sign-In
Future<UserCredential> signInWithGoogle() async {
final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser!.authentication;
final credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
return await FirebaseAuth.instance.signInWithCredential(credential);
}
Firestore CRUD Örneği
// Veri ekleme
await FirebaseFirestore.instance.collection('users').add({
'name': 'John Doe',
'email': '[email protected]',
'createdAt': FieldValue.serverTimestamp(),
});
// Veri okuma (real-time)
FirebaseFirestore.instance
.collection('users')
.snapshots()
.listen((snapshot) {
for (var doc in snapshot.docs) {
print(doc.data());
}
});
// Veri güncelleme
await FirebaseFirestore.instance
.collection('users')
.doc('userId')
.update({'name': 'Jane Doe'});
// Veri silme
await FirebaseFirestore.instance
.collection('users')
.doc('userId')
.delete();
Cloud Functions Örneği
// functions/index.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
// HTTP trigger
exports.helloWorld = functions.https.onRequest((req, res) => {
res.send('Hello from Firebase!');
});
// Firestore trigger
exports.onUserCreate = functions.firestore
.document('users/{userId}')
.onCreate(async (snap, context) => {
const user = snap.data();
// Hoşgeldin emaili gönder
await sendWelcomeEmail(user.email);
});
Güvenlik Kuralları
// firestore.rules
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Kullanıcılar sadece kendi verilerini okuyabilir
match /users/{userId} {
allow read, write: if request.auth != null
&& request.auth.uid == userId;
}
// Posts herkes okuyabilir, sadece auth kullanıcılar yazabilir
match /posts/{postId} {
allow read: if true;
allow create: if request.auth != null;
allow update, delete: if request.auth.uid == resource.data.authorId;
}
}
}
Fiyatlandırma İpuçları
- Spark planı (ücretsiz) ile başlayın
- Firestore okuma/yazma sayısını optimize edin
- Cloud Functions cold start'larına dikkat
- Storage için CDN kullanın
- Budget alerts ayarlayın
Alternatifler
- Supabase: Açık kaynak Firebase alternatifi, PostgreSQL
- AWS Amplify: Amazon'un BaaS çözümü
- Appwrite: Self-hosted BaaS
Firebase, mobil uygulama geliştirmeyi hızlandıran güçlü bir platformdur. Özellikle MVP'ler ve hızlı iterasyon gerektiren projeler için idealdir. Büyüdükçe maliyetleri kontrol altında tutmak için optimizasyon stratejileri uygulayın.