Why AppFig evaluates rules on the device
AppFig checks rules on the device so an app can react to what a user just did, offline and with no network call. Here are the trade-offs we accepted.
AppFig downloads your rules and evaluates them on the device, against events the SDK already holds there. We chose this because it is the only way an app can react to what a user did a second ago, with no network call and no connection.
The choice has costs, and we would rather explain them than have you find them later. This post covers what on-device evaluation makes possible, the two trade-offs we accepted, and what they mean for how you write rules.
What "on the device" means
There are two places a remote config service can decide which value a user gets. A server can decide: the app sends what it knows about the user, and the answer comes back. Or the app can decide: it receives the rules themselves and works out the answer locally.
AppFig does the second. The SDK loads the rule set at start-up and caches it. Your app logs events and sets properties, and the SDK keeps them on the device. When your code asks for a value, the SDK walks that feature's rules from top to bottom and returns the value of the first one that matches, or null when none does (how it works).
The only regular network traffic is the SDK asking a CDN whether the rule set has changed, every minute by default while the app is in the foreground, and downloading it when it has.
What it makes possible
Reacting to behavior immediately
This is the reason we built AppFig this way. Take a player who has just failed the same level twice. The useful moment to offer help is now, before they close the game. A rule for that looks like this:
{
"conditions": {
"events": {
"mode": "simple",
"operator": "AND",
"items": [
{ "key": "level_fail", "count": { "operator": ">=", "value": 2 }, "within_last_days": 1 }
]
}
},
"value": "on"
}
The app logs the event, and the next read sees it:
AppFig.LogEvent("level_fail");
if (AppFig.IsFeatureEnabled("offer_hint")) {
ShowHintOffer();
}
There is no pipeline between the event and the decision. The event is on the device, the rule is on the device, and the check happens when your code asks. If the decision were made on a server, the event would first have to travel there, be processed, and the app would have to ask again.
Rules can also look at order, not only counts. This one matches a user who opened the app, completed a level and then bought something, with other events allowed in between:
{
"mode": "sequence",
"ordering": "indirect",
"steps": [
{ "key": "app_open" },
{ "key": "level_complete" },
{ "key": "purchase_made" }
]
}
Event counts, recency, event parameters and sequences can be combined with user properties and device properties such as platform, OS version, language and country. The full list is in the rule schema.
Working offline
Mobile apps lose their connection in lifts, on trains and on planes, and games are played in all three. Because the rules are cached and the events are local, a rule keeps working with no connection. The player who fails twice in a tunnel still gets the hint.
No network call per check
Reading a value does not touch the network. The SDK evaluates the rules in memory and caches the result until relevant data changes, so a check costs microseconds, not a round trip. Your app never waits on our servers to draw a screen.
It is also why AppFig is priced per app and not per request: checks happen on the device, so how often your app reads a value never affects the price.
Events stay on the device
Behavioral targeting usually means sending a stream of user behavior to a vendor. With AppFig the event history that rules read is kept on the device and is not uploaded to us. On paid plans a small sample of devices reports event names, parameter names and example values, so the rule builder can offer them in its menus; the docs describe exactly what is sent, and it never includes event history (how it works).
For experiments, results are read from your own Google Analytics, so the measurement data stays in a tool you already control (experiments).
The trade-offs we accepted
Rules are visible on the device
A rule set that the device evaluates is a rule set the device has. Anyone determined enough can inspect what an app downloads, so treat your rules and their values as public.
In practice this means:
- No secrets in values. No API keys, no signing secrets, no private endpoints. A remote value is the wrong place for these in any system that delivers config to a client, and here the reason is especially plain.
- Nothing that must be enforced. A rule can decide who is shown a discount. It should not be the only thing that decides who is entitled to one. Checks that matter for money or access belong on your server or in the store's receipt validation.
- Unreleased plans are readable. If a variant value is called
black_friday_70_off, someone can read that before the sale.
We think this is the right trade for what remote config is used for: limits, timings, difficulty, layout, prices to display, which screen comes first. None of these are secrets once a user sees them.
The device has to hold the events
A rule can only count events the device still has. The SDKs keep up to 5,000 events for 7 days by default, and trim older ones. Both limits are settings: maxEvents goes up to 100,000 and maxEventAgeDays up to 365.
So if you write a rule with "within_last_days": 30, raise the event age to match:
AppFig.Init(
companyId: "acme-games",
tenantId: "space-shooter",
env: "prod",
apiKey: "sk_live_abc123",
maxEvents: 10000, // Store more events
maxEventAgeDays: 30 // Keep events for 30 days
);
It also means event history belongs to the device. For facts that should follow a person across devices or survive a reinstall, such as subscription tier or account age, set a user property from your own backend's data when the app starts:
AppFig.SetUserProperty("subscription_tier", "premium");
Use events for what happened recently in this app, and properties for what you know about the user for good.
Why we still think it is the right design
The things mobile teams most want to change are tied to moments: the third failed level, the first export, the second day. A system that learns about those moments later can report on them, but it cannot act in them. Putting the rules next to the events is what lets a product manager write "after two fails in a day, offer a hint" and have it be true on the next frame.
If you want to see where your own app would use this, the guided setup starts from your store link and suggests values to control.
FAQ
Does AppFig make a network call when I read a value?
No. Rules are evaluated on the device from data the SDK already holds. The SDK only contacts a CDN in the background to check whether the rule set has changed.
Do AppFig rules work offline?
Yes. The rule set is cached on the device and events are stored locally, so rules keep matching without a connection. New rules arrive the next time the device is online.
Can users see my rules?
Assume they can. The rules are downloaded to the device to be evaluated there, so do not put secrets in rule values and do not rely on a rule alone to enforce access or payment.
How long does the SDK keep events?
By default up to 5,000 events for 7 days. You can raise both with the maxEvents and maxEventAgeDays settings at initialization, up to 100,000 events and 365 days.
What happens when no rule matches?
The SDK returns null. Your code should always supply its own default, which is also what the app uses before any rules have loaded.