# Inngest Functions
Source: https://www.inngest.com/docs/learn/inngest-functions

import {
  RiGitPullRequestFill,
  RiGuideFill,
  RiTimeLine,
  RiCalendarLine,
  RiMistFill,
} from "@remixicon/react";

Inngest functions enable developers to run reliable background logic, from background jobs to complex workflows.
An Inngest Function is composed of 3 main parts that provide robust tools for retrying, scheduling, and coordinating complex sequences of operations:

<CardGroup cols={3}>
  <Card title="Triggers" icon={<EventIcon className="text-basis h-4 w-4"/>} href={'/docs/features/events-triggers'}>
    A list of Events, Cron schedules or webhook events that trigger Function runs.
  </Card>
  <Card title="Flow Control" icon={<RiGitPullRequestFill className="rotate-90 text-basis h-4 w-4" />} href={'/docs/guides/flow-control'}>
    Control how Function runs get distributed in time with Concurrency, Throttling and more.
  </Card>
  <Card title="Steps" icon={<RiGuideFill className="text-basis h-4 w-4"/>} href={'/docs/features/inngest-functions/steps-workflows'}>
    Transform your Inngest Function into a workflow with retriable checkpoints.
  </Card>
</CardGroup>

<GuideSelector options={[{ key: "typescript", title: "TypeScript" }, { key: "python", title: "Python" }, { key: "go", title: "Go" }]}>

<GuideSection show="typescript">

```ts
inngest.createFunction({
    id: "sync-systems",
    // Easily add Throttling with Flow Control
    throttle: { limit: 3, period: "1min"},
  },
  // A Function is triggered by events
  { event: "auto/sync.request" },
  async ({ step }) => {
    // step is retried if it throws an error
    await step.run("get-data", async () => {
      return getDataFromExternalSource();
    });

    // Steps can reuse data from previous ones
    await step.run("save-data", async () => {
      return db.syncs.insertOne(data);
    });
  }
);
```

</GuideSection>

<GuideSection show="python">

```python
@inngest_client.create_function(
    id="sync-systems",
    # trigger (event or cron)
    trigger=inngest.TriggerEvent(event="auto/sync.request"),
)
def sync_systems(ctx: inngest.ContextSync) -> None:
    # step is retried if it throws an error
    data = ctx.step.run("Get data", get_data_from_external_source)

    # Steps can reuse data from previous ones
    ctx.step.run("Save data", db.syncs.insert_one, data)
```

</GuideSection>

<GuideSection show="go">

```go
!snippet:path=snippets/go/docs/functions/sync_systems_function.go
```

</GuideSection>

</GuideSelector>

{/* 
Increase your Inngest Functions durability by leveraging:

- **[Retries features](/docs/guides/error-handling)** - Configure a custom retry policy, handle rollbacks and idempotency.
- **[Cancellation features](/docs/features/inngest-functions/cancellation)** - Dynamically or manually cancel in-progress runs to prevent unnecessary work.
- **[Versioning best practices](/docs/learn/versioning)** - Strategies to gracefully introducing changes in your Inngest Functions.
 */}

## Using Inngest Functions

Start using Inngest Functions by using the pattern that fits your use case:

<CardGroup cols={2}>
  <Card title="Background jobs" icon={<RiGuideFill className="text-basis h-4 w-4"/>} href={'/docs/guides/background-jobs'}>
    Run long-running tasks out of the critical path of a request.
  </Card>
  <Card title="Delayed Functions" icon={<RiCalendarLine className="text-basis h-4 w-4"/>} href={'/docs/guides/delayed-functions'}>
    Schedule Functions that run in the future.
  </Card>
  <Card title="Cron Functions" icon={<RiTimeLine className="text-basis h-4 w-4"/>} href={'/docs/guides/scheduled-functions'}>
    Build Inngest Functions as CRONs.
  </Card>
  <Card title="Workflows" icon={<RiMistFill className="text-basis h-4 w-4"/>} href={'/docs/guides/multi-step-functions'}>
    Start creating workflows by leveraging Inngest Function Steps.
  </Card>
</CardGroup>

## Learn more about Functions and Steps

Functions and Steps are powered by Inngest's Durable Execution Engine. Learn about its inner working by reading the following guides:

<CardGroup cols={1}>
  <Card title="How Functions are executed" icon={<RiMistFill className="text-basis h-4 w-4"/>} href={'/docs/learn/how-functions-are-executed'}>
    A deep dive into Inngest's Durable Execution Engine with a step-by-step workflow run example.
  </Card>
  <Card title="Thinking in Steps" icon={<RiGuideFill className="text-basis h-4 w-4"/>} href={'/docs/guides/multi-step-functions'}>
    Discover by example how steps enable more reliable and flexible functions with step-level error handling, conditional steps and waits.
  </Card>
</CardGroup>

## SDK References

<CardGroup cols={3}>

  <Card 
    href={"/docs/reference/typescript"}
    title={"TypeScript SDK"}
    icon={<TypeScriptIcon className="text-basis"/>}
  >
  API reference
  </Card>

  <Card 
    href={"/docs/reference/python"}
    title={"Python SDK"}
    icon={<PythonIcon className="text-basis"/>}
  >
    API reference
  </Card>

  <Card 
    href={"https://pkg.go.dev/github.com/inngest/inngestgo@v0.9.0/step"}
    title={"Go SDK"}
    icon={<GoIcon className="text-basis"/>}
  >
    Go API reference
  </Card>

</CardGroup>