Before applying BFF, a single backend handles all client types with conditional logic, making it complex and harder to maintain. After applying BFF, separate backend services handle web and mobile clients independently, simplifying logic and enabling client-specific optimizations.
### Before BFF (Single backend serving all clients)
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/data')
def data():
client = request.headers.get('Client-Type')
if client == 'web':
# Return full data with extra fields
return jsonify({'data': 'full data for web'})
elif client == 'mobile':
# Return limited data
return jsonify({'data': 'limited data for mobile'})
else:
return jsonify({'data': 'default data'})
### After BFF (Separate backend for web and mobile)
# Web BFF
from flask import Flask, jsonify
web_bff = Flask(__name__)
@web_bff.route('/data')
def web_data():
# Aggregate and enrich data for web client
data = {'data': 'full data for web'}
return jsonify(data)
# Mobile BFF
from flask import Flask, jsonify
mobile_bff = Flask(__name__)
@mobile_bff.route('/data')
def mobile_data():
# Aggregate and simplify data for mobile client
data = {'data': 'limited data for mobile'}
return jsonify(data)