How app serving works
Serving is the recommended way to deploy apps during development. It provides a faster feedback loop and allows you to dynamically modify inputs.
Overview
When you serve an app, the following happens:
- Code bundling: Your app code is bundled and prepared
- Image building: Container images are built (if needed)
- Deployment: The app is deployed to your Flyte cluster
- Activation: The app is automatically activated and ready to use
- URL generation: A URL is generated for accessing the app
Using the Python SDK
The simplest way to serve an app:
import flyte
import flyte.app
app_env = flyte.app.AppEnvironment(
name="my-dev-app",
inputs=[flyte.app.Input(name="model_path", value="s3://bucket/models/model.pkl")],
# ...
)
if __name__ == "__main__":
flyte.init_from_config()
app = flyte.serve(app_env)
print(f"App served at: {app.url}")Overriding inputs
One key advantage of serving is the ability to override inputs dynamically:
app = flyte.with_servecontext(
input_values={
"my-dev-app": {
"model_path": "s3://bucket/models/test-model.pkl",
}
}
).serve(app_env)This is useful for:
- Testing different configurations
- Using different models or data sources
- A/B testing during development
Advanced serving options
Use with_servecontext() for more control over the serving process:
Using CLI
You can also serve apps from the command line:
flyte serve path/to/app.py appWhere app is the variable name of the AppEnvironment object.
Return value
flyte.serve() returns an App object with:
url: The app’s URLendpoint: The app’s endpoint URLstatus: Current status of the appname: App name
app = flyte.serve(app_env)
print(f"URL: {app.url}")
print(f"Endpoint: {app.endpoint}")
print(f"Status: {app.status}")Best practices
- Use for development: App serving is ideal for development and testing.
- Override inputs: Take advantage of input overrides for testing different configurations.
- Quick iteration: Use
servefor rapid development cycles. - Switch to deploy: Use deploy for production deployments.
Troubleshooting
App not activating:
- Check cluster connectivity
- Verify app configuration is correct
- Review container logs for errors
Input overrides not working:
- Verify input names match exactly
- Check that inputs are defined in the app environment
- Ensure you’re using the
input_valuesparameter correctly
Slow serving:
- Images may need to be built (first time is slower).
- Large code bundles can slow down deployment.
- Check network connectivity to the cluster.