public void restore(byte[] snapshot) throws CannotRestoreSiddhiAppStateException {
        if (snapshot == null) {
            throw new CannotRestoreSiddhiAppStateException("Restoring of Siddhi app " + siddhiAppContext.
                    getName() + " failed due to no snapshot.");
        }
        Map<String, Map<String, Map<String, Map<String, Map<String, Object>>>>> fullSnapshot =
                (Map<String, Map<String, Map<String, Map<String, Map<String, Object>>>>>)
                        ByteSerializer.byteToObject(snapshot, siddhiAppContext);
        if (fullSnapshot == null) {
            throw new CannotRestoreSiddhiAppStateException("Restoring of Siddhi app " + siddhiAppContext.
                    getName() + " failed due to invalid snapshot.");
        }
        try {
            threadBarrier.lock();
            waitForSystemStabilization();
            try {
                //cleaning old group by states
                cleanGroupByStates();
                //restore data
                for (Map.Entry<String, Map<String, Map<String, Map<String, Map<String, Object>>>>> partitionIdSnapshot :
                        fullSnapshot.entrySet()) {
                    PartitionIdStateHolder partitionStateHolder = partitionIdStates.get(partitionIdSnapshot.getKey());
                    if (partitionStateHolder == null) {
                        continue;
                    }
                    for (Map.Entry<String, Map<String, Map<String, Map<String, Object>>>> partitionGroupByKeySnapshot :
                            partitionIdSnapshot.getValue().entrySet()) {
                        for (Map.Entry<String, Map<String, Map<String, Object>>> querySnapshot :
                                partitionGroupByKeySnapshot.getValue().entrySet()) {
                            ElementStateHolder elementStateHolder =
                                    partitionStateHolder.queryStateHolderMap.get(querySnapshot.getKey());
                            if (elementStateHolder == null) {
                                continue;
                            }
                            for (Map.Entry<String, Map<String, Object>> elementSnapshot :
                                    querySnapshot.getValue().entrySet()) {
                                StateHolder stateHolder =
                                        elementStateHolder.elementHolderMap.get(elementSnapshot.getKey());
                                if (stateHolder == null) {
                                    continue;
                                }
                                try {
                                    String partitionKey = null;
                                    String groupByKey = null;
                                    if (partitionGroupByKeySnapshot.getKey() != null) {
                                        String[] keys = partitionGroupByKeySnapshot.getKey().split("--");
                                        if (keys.length == 2) {
                                            if (!keys[0].equals("null")) {
                                                partitionKey = keys[0];
                                            }
                                            if (!keys[1].equals("null")) {
                                                groupByKey = keys[1];
                                            }
                                        }
                                    }
                                    SiddhiAppContext.startPartitionFlow(partitionKey);
                                    SiddhiAppContext.startGroupByFlow(groupByKey);
                                    State state = stateHolder.getState();
                                    try {
                                        if (state == null) {
                                            continue;
                                        }
                                        Map<String, Object> snapshotRestores = new HashMap<>();
                                        for (Map.Entry<String, Object> itemSnapshot :
                                                elementSnapshot.getValue().entrySet()) {
                                            if (itemSnapshot.getValue() instanceof Snapshot) {
                                                SnapshotStateList snapshotStateList = new SnapshotStateList();
                                                snapshotStateList.putSnapshotState(0L,
                                                        (Snapshot) itemSnapshot.getValue());
                                                snapshotRestores.put(itemSnapshot.getKey(), snapshotStateList);
                                            } else {
                                                snapshotRestores.put(itemSnapshot.getKey(),
                                                        itemSnapshot.getValue());
                                            }
                                        }
                                        state.restore(snapshotRestores);
                                    } finally {
                                        stateHolder.returnState(state);
                                    }
                                } finally {
                                    SiddhiAppContext.stopPartitionFlow();
                                    SiddhiAppContext.stopGroupByFlow();
                                }
                            }
                        }
                    }

                }
            } catch (Throwable t) {
                throw new CannotRestoreSiddhiAppStateException("Restoring of Siddhi app " +
                        siddhiAppContext.getName() + " not completed properly because content of Siddhi " +
                        "app has changed since last state persistence. Clean persistence store for a " +
                        "fresh deployment.", t);
            }
        } finally {
            threadBarrier.unlock();
        }
    }
Service level implementation to take/restore snapshots of processing elements.
Memory   : PartitionId + QueryName + ElementId + PartitionGroupByKey + Item
Snapshot : PartitionId + PartitionGroupByKey + QueryName + ElementId + Item
modules/siddhi-core/src/main/java/io/siddhi/core/util/snapshot/SnapshotService.java