a POC to learn gRPC, and playaround in a imaginary scenario, Where you want the use a ML model in python, but want to expose somesort other BACKEND to clients, for whatever reason:
- productivity
- performance
- security
- legacy
- stubbornness π
altho obviously you could do this over a stupid rest API.
Today I decided to do it over a stupid gRPC API, to reduce request latency, resource utilization and waste an evening.
Some client that
you convinced to use
your backend!
another server or
somesort of UI
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β SomeClient β β Node Backend β βPython Backendβ
βββββββββ¬βββββββ ββββββββ¬ββββββββ βββββββββ¬βββββββ
β β β
β β β
β POST: {transaction_id}β β
β /api/FraudActivity β β
ββββββββββββββββββββββββΊβ β
β+[AUTH/PERMISSION] β rpc: package fraud_detection: FraudDetectionService(PredictFraud)
β β ββββββ¬ββββββββββ
β ββββββββββββββββββββββββββββββββΌβββΊ β β
β βmessage PredictionRequest { β βLoad model
β β int64 transaction_id β β βΌ
β β double amount β βExtractsFeature
β β int64 time β β βΌ
β β int32 age_of_account β βDo Prediction
β β int32 number_of_transactions β β
β β} β β β
β β β β β
β ββββββββββββββββββββββββββββββββΌβββββ€ β
β β message PredictionResponse { ββββββΌββββββββββ
β β int64 transaction_id β
β β bool predicted_label β
β β double fraud_probability β
β β } β
βββββββββββββββββββββββββ€ β
β β β
β{ β β
β "transaction_id": "Y12a34x56", β
β "predicted_label": true, β
β "fraud_probability": 99.99, β
β} β β
β β β
β β β