Snowpark Container Services
Snowflake · Advanced Features
Theory
Snowpark Container Services (SPCS) runs your own container images inside Snowflake. You push an image to an image repository, a Snowflake registry that works with standard tools like the Docker CLI. A compute pool provides the virtual machine nodes, sized with an INSTANCE_FAMILY such as CPU_X64_XS or a GPU family, and scales between MIN_NODES and MAX_NODES. A service is a long-running container app, such as an API or web UI, defined by a YAML specification; Snowflake restarts its containers if they exit. A job service runs to completion, like a model training run.
For example, a custom Python scoring API can run as a service and be called from SQL through a service function, so the data never leaves Snowflake.
Why we use it
Some workloads do not fit SQL or Snowpark: custom runtimes, specialised libraries, GPUs or full web apps. SPCS runs them next to the data with Snowflake's security and roles, instead of a separate Kubernetes cluster and data copies.
When to use it
Use SPCS for custom APIs, ML training or inference on GPUs, and apps that need their own runtime. Use Snowpark UDFs or procedures when Python code alone is enough, since they need no images or pools. Suspend compute pools when idle because nodes bill while running.
How it works
- Build a container image locally
- Push it to a Snowflake image repository
- CREATE COMPUTE POOL with an instance family and node range
- Does the workload run forever or finish? Yes: CREATE SERVICE from a specification. No: EXECUTE JOB SERVICE for a finite run.
- Snowflake schedules containers on the pool's nodes
- Call it through an endpoint or a service function
Example
CREATE IMAGE REPOSITORY app_db.public.images;
CREATE COMPUTE POOL scoring_pool
MIN_NODES = 1
MAX_NODES = 2
INSTANCE_FAMILY = CPU_X64_XS
AUTO_SUSPEND_SECS = 600;
-- After docker push to the repository URL:
CREATE SERVICE scoring_service
IN COMPUTE POOL scoring_pool
FROM @app_db.public.specs
SPECIFICATION_FILE = 'scoring_spec.yaml';
SHOW SERVICES;
ALTER COMPUTE POOL scoring_pool SUSPEND;Key points
- Image repository, compute pool and service are the three core objects
- A service runs until stopped; a job service runs to completion
- Compute pools scale between MIN_NODES and MAX_NODES and can auto-suspend
- GPU instance families support training and inference
- Service functions let SQL send rows to a container for processing
- Compute pools also power notebook services in Workspaces