Shopify Functions allow developers to customize the backend logic of Shopify. This guide introduces how Shopify Functions work and the benefits of using Shopify Functions.
## How Shopify Functions work
Function [extension targets](/docs/apps/build/app-extensions/configure-app-extensions#targets) inject code into the backend logic of Shopify. The following diagram shows how Shopify invokes a function which has been configured for an extension target:
- **Function input:** The [function input](/docs/apps/build/functions/input-output#input) is a JSON object which is the result of a GraphQL input query you define. Input queries allow you to select the specific data you need for your function, such as cart line product data or metafields.
- **Function logic:** The function logic is written in any language that can compile a WebAssembly module which meets [function requirements](/docs/apps/build/functions/programming-languages/webassembly-for-functions). Function templates and client libraries are available for [Rust](/docs/apps/build/functions/programming-languages/rust-for-functions) and [JavaScript](/docs/apps/build/functions/programming-languages/javascript-for-functions).
> Caution:
> Shopify strongly recommends [Rust](/docs/apps/build/functions/programming-languages/rust-for-functions) as the most performant language choice to avoid your function failing with large carts.
- **Function output:** The [function output](/docs/apps/build/functions/input-output#output) is a JSON document that describes the operations you'd like Shopify to carry out.
GraphQL schemas provided by Shopify specify the targets, available inputs, and expected outputs for a [Functions API](/docs/api/functions).
## Lifecycle of a Shopify Function
The following diagram shows an example lifecycle of a Shopify Function:
- **App developers** create and deploy apps that contain functions.
- **Merchants** install the app on their Shopify store and configure the function. An API call is made with the function configuration.
- **Customers** interact with a Shopify store and **Shopify** executes the function.
For example, an app developer might create and deploy an app with a function that defines a new discount type. The merchant can then install the app on their Shopify store and create a new discount from a discount type provided by the app. Shopify executes the function to calculate the discount when a customer adds a product to their cart.
Shopify Functions are never invoked directly by URL or otherwise. Shopify invokes them as-needed within the customer journey.
![A diagram showing the creating and deploying phases in Shopify Functions](/assets/api/functions/create-test-deploy.png)
## Getting started
Learn how to use Shopify Functions by following one of our use case tutorials:
## API versions
Function APIs are [versioned](/docs/api/usage/versioning). Updates are released quarterly and supported API versions are listed in the [release notes](/docs/api/release-notes).
[Learn how to update to a new version of a Function API](/docs/apps/build/functions/input-output#api-versions).
## Limitations and considerations
The following limitations and considerations apply to all functions:
- Apps can reference only their own functions in GraphQL Admin API mutations, such as [`discountAutomaticAppCreate`](/docs/api/admin-graphql/latest/mutations/discountAutomaticAppCreate) and [`cartTransformCreate`](/docs/api/admin-graphql/latest/mutations/cartTransformCreate). Referencing a function from another app results in a `Function not found` error.
- Shopify doesn't allow nondeterminism in functions, which means that you can't use any randomizing or clock functionality in your functions.
- You can't debug your function by printing out `STDOUT`, which is reserved for function output. Use `STDERR` instead.
- Apps that provide dynamic editing and execution of function code aren't permitted on the Shopify App Store.
- Network access is supported for some functions, refer to [network access](/docs/apps/build/functions/input-output/network-access) for more information. You can also pre-populate data by using metafields on products and customers, or passing data using cart attributes.
## Resource limits
> Note:
> Function resource limits treat 1 kilobyte (kB) as 1000 bytes.
### Fixed limits
The following resource limits apply to all functions:
| Resource | Limit |
|-|-|
| Compiled binary size | 256 kB |
| Runtime linear memory | 10,000 kB |
| Runtime stack memory | 512 kB |
| Logs written to `STDERR` | 1 kB (truncated) |
### Dynamic limits
Certain limits are dynamic and scale based on the number of line items in a cart. The following resource limits apply to all functions for carts with up to 200 line items:
| Resource | Limit (up to 200 line items) |
|-|-|
| Execution [instruction count](https://webassembly.github.io/spec/core/syntax/instructions.html) | 11 million instructions |
| Function input | 128 kB |
| Function output | 20 kB |
For carts with more than 200 line items, these values will scale proportionally as the number of cart lines increases. Calculated limits for a function execution are available in your Partner Dashboard and can be [tested with Shopify CLI](/docs/apps/build/functions/test-debug-functions#execute-the-function-locally-using-shopify-cli).
## Deleting functions
To delete a Shopify Function, you need to remove the relevant files from your app's `/extensions` directory, and then redeploy your app. [Learn more about removing a Shopify Function](/docs/apps/build/app-extensions/remove-app-extension#remove-a-cli-managed-app-extension).
When you delete a function, the following behavior occurs:
- The function, including all associated [function owners](/docs/apps/build/functions/input-output/metafields-for-input-queries#how-it-works), is permanently deleted.
- The function no longer runs, and becomes inaccessible to any Shopify stores that have your app installed.
## Next steps
- Learn about how data is [input to and output from Shopify Functions](/docs/apps/build/functions/input-output).
- Explore [the references for each Function API](/docs/api/functions).