> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gorules.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Embedded SDK deployment

> Bundle the rules engine directly into your application for maximum performance.

export const SdkOverview = () => {
  const sdks = [{
    name: 'Node.js',
    href: '/developers/sdks/nodejs',
    icon: 'node-js',
    color: '#68a063'
  }, {
    name: 'Python',
    href: '/developers/sdks/python',
    icon: 'python',
    color: '#3776ab'
  }, {
    name: 'Go',
    href: '/developers/sdks/go',
    icon: 'golang',
    color: '#00add8'
  }, {
    name: 'Rust',
    href: '/developers/sdks/rust',
    icon: 'rust',
    color: '#ce422b'
  }, {
    name: 'Java',
    href: '/developers/sdks/java',
    icon: 'java',
    color: '#e76f00'
  }, {
    name: 'Kotlin',
    href: '/developers/sdks/kotlin',
    icon: '/images/kotlin.svg',
    color: '#7f52ff'
  }, {
    name: 'C#',
    href: '/developers/sdks/csharp',
    icon: '/images/dotnet.svg',
    color: '#512bd4'
  }, {
    name: 'Swift',
    href: '/developers/sdks/swift',
    icon: 'swift',
    color: '#f05138'
  }, {
    name: 'WASM',
    href: '/developers/sdks/wasm',
    icon: '/images/wasm.svg',
    color: '#654ff0'
  }];
  return <div style={{
    display: 'grid',
    gridTemplateColumns: 'repeat(4, 1fr)',
    gap: '12px',
    margin: '16px 0'
  }}>
      {sdks.map(sdk => <a key={sdk.name} href={sdk.href} style={{
    display: 'flex',
    alignItems: 'center',
    gap: '10px',
    padding: '14px 16px',
    borderRadius: '8px',
    backgroundColor: '#f8fafc',
    border: '1px solid #e2e8f0',
    textDecoration: 'none'
  }}>
          <Icon icon={sdk.icon} size={18} color={sdk.color} className="my-0" />
          <span style={{
    fontSize: '14px',
    fontWeight: 500,
    color: '#1e293b'
  }}>
            {sdk.name}
          </span>
        </a>)}
    </div>;
};

Embed the ZEN Engine directly in your application using native SDKs. This deployment model provides the highest performance with no network overhead.

## When to use embedded

**Choose embedded when you need:**

* Maximum evaluation performance (sub-millisecond latency)
* Offline capability
* No external service dependencies
* Direct control over the engine lifecycle

**Consider alternatives when:**

* Multiple services need the same rules
* You want centralized rule management
* Business users need to update rules without deployments

## Architecture

```mermaid theme={null}
flowchart TB
    subgraph app["Your Application"]
        subgraph sdk["ZEN Engine SDK"]
            decision["Decision (JDM)"]
        end
    end
```

The engine runs in-process. Decision files are loaded at startup or runtime.

## SDKs

<SdkOverview />

## Loading decisions

### Bundle with your application

Include decision files in your deployment package:

<Tree>
  <Tree.Folder name="my-app" defaultOpen>
    <Tree.Folder name="src" />

    <Tree.Folder name="rules" defaultOpen>
      <Tree.File name="pricing.json" />

      <Tree.File name="eligibility.json" />

      <Tree.File name="risk-scoring.json" />
    </Tree.Folder>

    <Tree.File name="package.json" />
  </Tree.Folder>
</Tree>

Load at application startup:

```javascript theme={null}
import { ZenEngine, ZenDecisionContent } from '@gorules/zen-engine';
import fs from 'fs';
import path from 'path';

const rulesDir = path.join(__dirname, 'rules');

// Precompile decisions into a cache - ZenDecisionContent compiles for better performance
const decisionCache = new Map();
decisionCache.set('pricing.json', new ZenDecisionContent(
  fs.readFileSync(path.join(rulesDir, 'pricing.json'))
));
decisionCache.set('eligibility.json', new ZenDecisionContent(
  fs.readFileSync(path.join(rulesDir, 'eligibility.json'))
));

// Create engine with a loader that returns precompiled decisions
const engine = new ZenEngine({
  loader: async (key) => decisionCache.get(key),
});

// Evaluate by decision name
const result = await engine.evaluate('pricing.json', { customer: { tier: 'gold' } });
```

### Fetch from remote storage

Load decisions from S3, GCS, or HTTP endpoints:

```javascript theme={null}
import { ZenEngine, ZenDecisionContent } from '@gorules/zen-engine';

const decisionCache = new Map();

// Loader fetches and precompiles decisions on demand
const loader = async (key) => {
  if (decisionCache.has(key)) {
    return decisionCache.get(key);
  }

  const response = await fetch(`${process.env.RULES_URL}/${key}`);
  const buffer = Buffer.from(await response.arrayBuffer());
  const content = new ZenDecisionContent(buffer);

  decisionCache.set(key, content);
  return content;
};

const engine = new ZenEngine({ loader });

// Evaluate - loader fetches and caches automatically
const result = await engine.evaluate('pricing.json', { customer: { tier: 'gold' } });
```

### Hot reloading

Update decisions without restarting:

```javascript theme={null}
import { ZenEngine, ZenDecisionContent } from '@gorules/zen-engine';

class DecisionManager {
  constructor() {
    this.cache = new Map();
    this.engine = new ZenEngine({
      loader: async (key) => this.cache.get(key),
    });
  }

  load(name, buffer) {
    // Precompile and cache
    this.cache.set(name, new ZenDecisionContent(buffer));
  }

  reload(name, buffer) {
    // Atomic swap - precompile new content and replace
    this.cache.set(name, new ZenDecisionContent(buffer));
  }

  async evaluate(name, input) {
    return this.engine.evaluate(name, input);
  }
}
```

## Best practices

**Initialize once** — Create engine and decisions at startup, not per-request.

**Handle errors gracefully** — Decision loading can fail. Have fallback behavior.

**Version your rules** — Track which rule version is deployed with your application.

**Test thoroughly** — Rule changes ship with code changes. Include rule tests in your CI/CD.

## Updating rules

With embedded deployment, updating rules requires redeploying your application:

1. Export updated rules from BRMS
2. Add to your repository
3. Deploy application with new rules

For more dynamic updates, consider the [Agent deployment](/developers/deployment/agent) model.
